- What outputs do the following sets of code produce?
# Quick calculation.
numberA = 42
numberB = 3.142
yourAnswer = 100
if numberA + numberB >= yourAnswer:
print("That's interesting.")
else:
print("Good effort.")
# Cool calculator
yearsOld = 12
daysOld = 365.25 * yearsOld
if daysOld > 7300:
print("You are really old")
elif daysOld > 5000:
print("You're getting on a bit")
else:
print("You're young and happening!")
print("Thank you for playing")
# Poorly scored quiz...
score = 0
capitalEngland = "London"
capitalAustralia = "Sydney"
capitalFrance = "Paris"
if capitalEngland == "London" or capitalEngland == "LONDON":
score += 1
if capitalAustralia == "Canberra" and capitalFrance == "Paris":
score +=2
print("You scored: " + str(score))
# The drinks machine
wantsTea = True
wantsSugar = False
wantsMilk = True
if wantsTea == True:
if wantsSugar == True:
if wantsMilk == True:
print("Drink A")
else:
print("Drink B.")
else:
if wantsMilk == True:
print("Drink C")
else:
print("Drink D")
else:
print("Drink E")
# Used car value calculator...
carMake = "Morris"
newPrice = 4000
condition = "Good"
if carMake == "Fjord" or carMake = "Austin":
discount = 0.8
elif carMake == "Morris:"
discount = 0.5
else:
discount = 0.75
usedPrice = newPrice * discount
if condition == "Excellent":
discount = 0.8
elif condition == "Good" or condition == "Fair":
discount = 0.75
else:
discount = 0.5
usedPrice = usedPrice * discount
print("It's worth £" + str(usedPrice))
- Answers to be submitted as a text file, uploaded into the homework 3 badge on BourneToLearn.