Week 3: Exercise Solutions

Exercise 3.1

Exercise 3.2

Exercise 3.3

# To calculate body mass index
height = float(input("What is your height in metres? "))
weight = float(input("What is your weight in kilos? "))
print("Your BMI is", weight / height**2)

Exercise 3.4

# To decide if a number is non-zero
number = int(input("Enter an integer: "))
print("It is", number != 0, "that your number is non-zero")

Exercise 3.5

In the first case, the condition is always true so the program will just print

Spam and eggs

over and over again forever and will never print Lobster thermidor.

In the second case the condition is never true, so will not print anything about spam but will only print Lobster thermidor.