Branching If Else
if else simplest.py
if True:
print("If true, this will print.") #this
else:
print("If false, this will print.") #not this
if False:
print("If true, this will print.") #not this
else:
print("If false, this will print.") #this
if else simpler.py
if (5 > 1):
print("5 is greater than 1...")
print("Program should branch this way. All is fine.")
else:
print("5 isn't greater than 1...")
print("Something has gone wrong if you are seeing this.")
if else simple.py
temperature = 5 #degrees
if temperature < 15:
print("Wear a jumper")
else:
print("Wear a tshirt")
if else.py
passMark = 5
score = int(input("What was your score out of 10?"))
if score >= passMark:
print("You passed! Congratulations.")
else:
print("Better luck next time.")
if else inline.py
aBoolean = True
print("well that was true") if aBoolean else print("no it wasn't")
- write a program that inputs the current temperature as a whole number (celcius) and tells me whether it is hot or cold (lets assume hot is anything 20 or over, everything else is cold).
- input a whole number. if the number inputted is less than 0, say "Negative number". If the number is 0 or above, say "Positive number".
- input the money i have in my wallet. check whether i have $1.80 to afford a coke. if the amount i enter is less than $1.80, say "not enough change", else say "enjoy your drink".