Adding numbers and joining text look the same, but they are different.
The str is there, but not in the right place.
Fill in what each line shows.
line
shows
print("Score: " + str(score))
Score: 5
print("Score: " + str(score + 1))
print(score + score)
print(str(score) + str(score))
This should show Lives: 3, but stops with an error. Click the line that still has the problem.
ModifyChange the code on purpose and check the result.
Modify
Change the program so it also prints how many letters the name has.
Try it yourselfYour edits are saved in this browser.
Need a hint?
len(name) gives the number of letters. It is a number, so it needs str.
Print how many letters the name has, such as Ada has 3 letters.
Run your program. This ticks when your code does all of the above.
InvestigateTrace how each line of code connects to what you see.
Mix it up
Mix of the last two lessons: the answer is stored, a number is worked out from it, and the number is turned into text.
lesson.py
name = input("What is your name? ")
count = len(name)
print(name + " has " + str(count) + " letters.")
MakeBuild something new using what you have learned. Expect a few tries; that is normal.
Make
A café sells cups of hot chocolate. Write a receipt: store the number of cups and the price, work out the total, and print a line such as 3 cups cost $12.
Try it yourselfYour edits are saved in this browser.
Need a hint?
Work out the total first: total = cups * price. Then turn it into text in the print line.
Another hint
Each number joined onto text needs its own str().
Print a receipt line that joins a count and a calculated total with text.
Run your program. This ticks when your code does all of the above.
For teachers
Students learn why a number cannot be joined onto text with + and fix it with str. About 30 minutes.