Strings Practice Quiz¶
To confirm that you understand the string concepts you’ve seen in Python, try to answer the following questions without opening Python.
Question 1¶
strings-quiz1: In the following code, what does this code print?:
sentence = "python rocks"
print(sentence[5])
Question 2¶
strings-quiz2: In the following code, what does this code print?:
sentence = "python rocks"
print(sentence[2] + sentence[-3])
Question 3¶
strings-quiz3: In the following code, how many times is the word “Saskatchewan” printed?:
word = "practice"
for character in word:
print("Saskatchewan")
Question 4¶
strings-quiz4: In the following code, what does this code print?:
sentence = "Walter Murray Collegiate Institute"
print(sentence[8:12])
Question 5¶
strings-quiz5: In the following code, what does this code print?:
sentence = "Walter Murray Collegiate Institute"
print(sentence[2:8])
Question 6¶
strings-quiz6: In the following code, what does this code print?:
sentence = "Walter Murray Collegiate Institute"
print(sentence[:9])
Question 7¶
strings-quiz7: In the following code, what does this code print?:
sentence = "Greenall"
print(len(sentence))
Question 8¶
strings-quiz8: In the following code, what does this code print?:
place = "sask"
thing = ""
for item in place:
thing = thing + item
print(thing)
Question 9¶
strings-quiz9: In the following code, what does this code print?:
place = "sask"
thing = ""
for item in place:
thing = item + thing
print(thing)
Question 10¶
strings-quiz10: In the following code, what does this code print?:
def apply_rule(character):
new_character = ""
if character == "X":
new_character = "XYF"
elif character == "Y":
new_character = "FXY"
else:
new_character = character
return new_character
print(apply_rule("Y"))
Question 11¶
strings-quiz11: In the following code, what does this code print?:
def apply_rule(character):
new_character = ""
if character == "X":
new_character = "XYF"
elif character == "Y":
new_character = "FXY"
else:
new_character = character
return new_character
def process_string(some_string):
new_string = ""
for character in some_string:
new_string = new_string + apply_rule(character)
return new_string
print(process_string("XZY"))