Presentation is loading. Please wait.

Presentation is loading. Please wait.

GCSE COMPUTER SCIENCE Practical Programming using Python

Similar presentations


Presentation on theme: "GCSE COMPUTER SCIENCE Practical Programming using Python"— Presentation transcript:

1 GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 6 – String Manipulation

2 Screenshot the result of this code:
String Manipulation Python has a lot of built in methods that allow us to easily manipulate (change) strings. The len method counts the number of characters in a string. Try it for yourself. Screenshot the result of this code: Save the program as stringlen.

3 Write the following Python program and press F5 to run.
Activity 1 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string1.

4 Write the following Python program and press F5 to run.
Activity 2 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string2.

5 Write the following Python program and press F5 to run.
Activity 3 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string3.

6 Write the following Python program and press F5 to run.
Activity 4 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string4.

7 Write the following Python program and press F5 to run.
Activity 5 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string5.

8 Write the following Python program and press F5 to run.
Activity 6 Write the following Python program and press F5 to run. Explain what this code does: Save the program as string6.

9 Write the following Python program and press F5 to run.
Activity 7 Write the following Python program and press F5 to run. #returns a True or False value text = (“I love Computer Science”) print(“C” in text) Explain what this code does: Save the program as string7.

10 Write the following Python program and press F5 to run.
Activity 8 Write the following Python program and press F5 to run. #returns the position, only finds first instance text = (“I love coming to school each day”) print(text.find(“m”)) Explain what this code does: Save the program as string8.

11 String Formatting {:^15} {:<10} {:>20} Example
You can use string formatting to get greater control over how strings are displayed on screen. We create placeholders for the string, each placeholder is enclosed inside curly brackets. {:^15} This example creates a placeholder that is 15 characters in length and whatever is placed inside it will be centred. {:<10} 10 characters in length and left aligned. {:>20} 20 characters in length and right aligned. Example

12 Write the following Python program and press F5 to run.
Activity 9 Write the following Python program and press F5 to run. Write a program that outputs your first name and last name under those same headings. It should use 15 characters for each and be centre aligned. Use the example to help you. Place a screenshot of your code here Save the program as string9.

13 Write the following Python program and press F5 to run.
Activity 10 Write the following Python program and press F5 to run. Write a program that outputs your first name and your age under those same headings. It should use 20 characters for each and be left aligned. Place a screenshot of your code here Save the program as string10.

14 Write the following Python program and press F5 to run.
Activity 11 Write the following Python program and press F5 to run. Write a program that outputs the date and the time under those same headings. It should use 10 characters for each and be right aligned. Place a screenshot of your code here Save the program as string11.


Download ppt "GCSE COMPUTER SCIENCE Practical Programming using Python"

Similar presentations


Ads by Google