Making Choices π
Real programs make decisions. Python uses if and else:
If something is true, do this. Else (otherwise), do that.
def weather(rainy):
if rainy:
return "umbrella β"
else:
return "sunglasses π"
Two important things about Python:
- There are no braces
{}. Instead, the indentation (4 spaces) shows what's inside theif. - The line ends with a colon
:.
If rainy is true, it returns the umbrella. Otherwise, the sunglasses. Read it
carefully, then answer below. π