Conditional statemet exercises

Download notebook Interact

Exercises on conditional statements

For background, please read the conditional statements introduction.

This if statement is not properly defined, and will give a SyntaxError. Fix it, then run to confirm it prints 'x greater than 4':

x = 10
x > 4:
    print('x greater than 4')

This if statement also gives a SyntaxError. Fix and run. It should print -8;

p = -2
if p < 0
    p = p * 4
print(p)

Another SyntaxError; fix and run. It should print a divided by 6 is 4

a = 24
if a / 6 == 4:
print('a divided by 6 is 4')

We want an algorithm to choose a newspaper for someone to read in the dentist’s waiting room, given what we know about their views on Brexit.

Write a cell that prints Times if voter has the value Soft Brexit, otherwise prints Telegraph if voter has the value Hard Brexit otherwise prints Guardian if voter has value remain, otherwise prints No idea.

# Try for different values of voter
voter = 'Hard Brexit'
# Your code here
if voter ...