Tutorial code: tu05
SCORE: 12 points
PYTHON HAS A STING
When Python was originally made by Guido. He'd clearly read his fair share of atrociously written code and for that reason. Guido has insisted all Python is correctly indented. You don't indent, your program won't work!
An IF statement can test many things. On this occasion it is simply looking for the character "y" and I mean a lowercase y. That's your first hint that Python IS case sensitive!
Exercise 1: Paste in the following code. What happens if you:
a. Remove the indent
b. Type in a capital Y
c. Change the "y" to "Y"
a. Remove the indent
b. Type in a capital Y
c. Change the "y" to "Y"
Being more flexible - change == to in
At this point it would be handy to let people enter y or Y. To do this in Python the easiest way is to do the following:
if test in ["y","Y"]:
Notice how the == is now in This is because we do not want to match everything, but just one item in the list.
if test in ["y","Y"]:
Notice how the == is now in This is because we do not want to match everything, but just one item in the list.
Exercise 2: Change the code to be more flexible. Can you also allow 'yes" too?
Exercise 3
It would be great to add a statement that if it's not raining, we can play. Have a look at this code.
else:
print("Great we can play!")
What's wrong with it?
Exercise 3
It would be great to add a statement that if it's not raining, we can play. Have a look at this code.
else:
print("Great we can play!")
What's wrong with it?