Exercises
Syntax
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Indent the two print calls so both belong to the if.
Python
temperature = 31
if temperature > 30:
print("Hot")
print("Drink water")Everything that belongs to the if goes four spaces to the right.
temperature = 31
if temperature > 30:
print("Hot")
print("Drink water")Exercise 2Passed
The block under the def is empty and will not run. Add the one statement that legally does nothing.
Python
def later():
print("reached the end")There is a keyword whose whole job is to occupy a block.
def later():
pass
print("reached the end")Exercise 3Passed
Split this into three separate statements, one per line, so it prints 3.
Python
first = 1; second = 2; print(first + second)Python ends a statement at the newline. The semicolons are not needed.
first = 1
second = 2
print(first + second)