Below you’ll see some example python code that will output three things to the screen.
Press Ctrl + Enter to run the code.
Click on your score in the top right corner of the code editor to see what your code needs to do.
Any line of code that starts with a # is a comment: it doesn’t affect how the program runs, it’s just there to help explain what the code does.
- Change line 3 so it displays an ! after your name
You’ll need to surround the
!with quotes (
"!") and then add it on to the text to be displayed after the variable
Joining together text and / or variables is called concatenation. If text is surrounded with quotes (e.g.
"name") , it’ll use that text literally as you’ve written it.
If text is not surrounded with quotes it will use that text as a variable name and try to find the value stored in that variable.
- Change line 7 so that it will say “chips? I love chips!” or “pizza? I love pizza!”
Be careful with quotation marks – you’ll need to use the food variable twice in this line of code.
- Change line 10 so that it will show your favourite word 100 times
At the moment, whatever you input as your favourite word will be displayed 10 times because
word * 10multiplies (repeats) whatever is stored in the
wordvariable 10 times.
On the next page you’ll get some code examples that have been deliberately broken for you to try to fix.