WorksheetsChapter 6
Total questions: 10
Worksheet time: 3mins
Emma is preparing a greeting message for her friend. She has two strings: one containing "Hello" and the other containing 'there'. She combines these two strings to create a message. What does the following Python Program print out? str1 = "Hello" str2 = 'there' bob = str1 + str2 print(bob)
Hello there
Hellothere
Hello
there
Avery has a string representing a number: x = '40'. She wants to add 2 to this number and print the result. What does the following Python program print out? x = '40' y = int(x) + 2 print(y)
x2
42
int402
402
How would you use string slicing [:] to print out 'uct' from the following string? x = 'Noah's email is marquard@uct.ac.za'
print(x[14:17])
print(x[15:3])
print(x[14+17])
print(x[14:3])
print(x[14/17])
In a fruit shop, Noah is sorting through a basket of bananas. For each banana he picks up, he says its name aloud. What is the iteration variable in the following Python code? for letter in 'banana' : print(letter)
for
in
'banana'
letter
Hannah is making banana smoothies for a party. She knows that each smoothie requires 7 bananas. If she has a total of 6 bananas, how many bananas will she need to make 6 smoothies? print(len('banana')*7)
42
-1
banana7
banana banana banana banana banana banana banana
Abigail is learning Python and is exploring different string methods to manipulate text. She comes across a list of methods and wonders which one is not a valid string method in Python. Which of the following is not a valid string method in Python?
boldface()
upper()
lower()
lstrip()
startswith()
Grace is working on a project where she needs to clean up user input data. She realizes that some strings have unnecessary spaces at the beginning and end. Which of the following string methods should she use to remove whitespace from both the beginning and end of a string?
wsrem()
strip()
split()
strtrunc()
