Conditional Statements
First Function:drink(money)
drink(money)
def drink(money):
if money >= 2:
return "You've got yourself a drink!"
else:
return "No drink for you!"
print(drink(4)) # Enough money → drink
print(drink(1)) # Not enough → no drink
Explanation:
If money is 2 or more, it returns a success message.
Otherwise, it returns a rejection message.
Output:

Second Function:alcohol(age, money)
alcohol(age, money)
def alcohol(age, money):
if (age >= 21) and (money >= 5):
return "We're getting a drink!"
elif (age >= 21) and (money < 5):
return "Come back with more money!"
elif (age < 21) and (money >= 5):
return "Nice try, kiddo!"
else:
return "You're too poor and too young!"
print(alcohol(21, 5)) # Age and money OK
print(alcohol(21, 3)) # Old enough but not enough money
print(alcohol(18, 10)) # Too young
print(alcohol(15, 3)) # Too young and poor
Explanation:
Checks both age and money using
if
,elif
, andelse
.Uses
and
to combine conditions.
Output:

#!/bin/python3
# Conditional Statements
def drink(money):
if money >= 2:
return "You've got yourself a drink!"
else:
return "No drink for you!"
print(drink(4))
print(drink(1))
def alcohol(age,money):
if (age >= 21) and (money >= 5):
return "We're getting a drink!"
elif (age >= 21) and (money < 5):
return "Come back with more money!"
elif (age < 21) and (money >= 5):
return "Nice try,kiddo!"
else:
return "You're too poor and too young!"
print(alcohol(21,5))
print(alcohol(21,3))
print(alcohol(18,10))
print(alcohol(15,3))
Last updated