Search Header Logo
2.2 String Manipulation

2.2 String Manipulation

Assessment

Presentation

Computers

10th Grade

Practice Problem

Medium

Created by

Leah Tomlinson

Used 9+ times

FREE Resource

11 Slides • 4 Questions

1

2.2 String Manipulation

Work through the slides and questions independently, then complete the tasks attached to the assignment in google classroom.

Slide image

2

Multiple Choice

Which of the following code is a function?

1

def addition(num1, num2):

total = num1 + num2

print(total)


#main program

addition(3,6)

2

def addition(num1, num2):

total = num1 + num2

return total


#main total

sum = addition(3,6)

print(sum)

3

Multiple Choice

What is the difference between a procedure and a function?

1

A function has parameters a procedure does not

2

A function contains calculations a procedure does not

3

A function needs to return a value to the main program a procedure does not

4

Slide image

Sometimes when programming we want to chop and change our strings to meet the needs of the program. For example, you might have an input which asks a user for their first and last name. The program you develop might need that input to be split into two separate variables, Python has string manipulation tools which allow us to do this.

5

Slide image

Above are the different ways we can manipulate strings to suit our program needs. You may have used some of them before in programming or they could be completely new to you. I have included a link to a website which shows you how to use each of them in python.

6

Slide image

Complete this task, open the presentation posted in Google Classroom, you need to match the first sets of code to an alternative way of writing it and then match it to the description of what it does.

7

Multiple Choice

When wanting to find the length of a string, which code would you use?

1

length(string)

2

length = string.length

3

length = len(string)

8

Multiple Choice

What would the code 'name.substring(3,5)' return?

1

5 characters in the string starting from the 3rd

2

3 characters in the string starting from the 5th

3

The 3rd to the 5th character in the string

9

Slide image

Here we have an example of a string "Freda Smith", in the table at the bottom. Here we have first taken a substring starting at position 1 and ending in position 3 resulting in the string "RED". In the second example we are trying to find the location of "S", so the function will search the string find the index and return it. Finally, we use the length function to find how long the string is, in this example "11"

10

Slide image

Complete the task posted in the assignment, for this task you need to say what the output would be using the string for each line of code/

11

Slide image

ASCII is an internationally used character set which gives every character its own unique binary code using up to 32 bits. The function ASC("A") would return the decimal number the character represents, in this case 65. The "A" can be substituted for any number. The CHR(66) function will do the opposite, again "66" can be substituted for any number.

12

Slide image

For this task you need to work through the algorithm to identify what the value of each variable will be when the algorithm has completed.

13

Slide image

There are 5 tasks which require you to complete string manipulation, some of them just require you to fill in the blanks and others require you to write the full algorithm. These can be written using Python just ensure that all syntax is correct.

14

Slide image

Final task is some exam style questions on String manipulation, ensure you consider the number of marks available when writing your answer. They are all algorithm questions and so again Syntax will need to be as accurate as possible if writing in Python.

15

Slide image

The tasks discussed are due in today (Wednesday 20th) you should have also completed and uploaded the tasks from Mondays lesson - subprograms.

2.2 String Manipulation

Work through the slides and questions independently, then complete the tasks attached to the assignment in google classroom.

Slide image

Show answer

Auto Play

Slide 1 / 15

SLIDE