if x < y:
…
elif x > y:
…
else :
…
if x < y or x > y:
…
else:
…
if x != y:
…
else:
…
if score >= 90 and score <= 100:
…
if 90 <= score <= 100:
…
if score >= 90:
…
Remainder of dividing two numbers not evenly
4 % 2 = 0 (divides evenly)
3 % 2 = 1 (dividing 3/2 = 1.5, the quotient is 1 and the remainder 0.5 x 2 = 1)
16 % 5 = 1 (dividing 16/5 = 3.2, the quotient is 3 and the remainder 0.2 x 5 = 1)
if x % 2 == 0:
print("Even")
else:
print("Odd")
def is_even(n):
if n % 2 == 0:
return True
else:
return False
Pythonic syntax
def is_even(n):
return True if n % 2 == 0 else False
def is_even(n):
return n % 2 == 0 # The operation automatically returns a bool
# Integrating `is_even()`
if is_even(x):
print("Even")
name = input("What’s your name? ")
if name == "Harry":
print("Gryffindor")
elif name == "Harry":
print("Gryffindor")
elif name == "Harry":
print("Gryffindor")
elif name == "Draco":
print("Slytherin")
else :
print("Who?")
name = input("What's your name? ")
if name == "Harry" or "Hermione" or "Draco":
print("Gryffindor")
elif name == "Draco":
print("Slytherin")
else :
print("Who?")
match
name = input("What’s your name? ")
match name:
case "Harry":
print("Gryffindor")
case “Hermione”:
print("Gryffindor")
case “Ron”:
print("Gryffindor")
case “Draco”:
print("Slytherin")
case _:
print("Who?")
match name:
case "Harry" | "Hermione" | "Ron":
print("Gryffindor")
case "Draco":
print("Slytherin")
case _:
print("Who?")
def main():
difficulty = ("Enter level: ")
if not (difficulty == "Difficult" or difficulty == "Casual"):
print("Enter a valid difficulty")
return
if difficulty == "Difficult":
if players == "Multiplayer":
recommend("Poker")
if difficulty == "Difficult" and players == "Multiplayer":
recommend("Poker")