Updated 10/13/2020
What We’ll Cover
- Various features in Python you may not have known about!
- These various features in action!
- Russian Roulette!
What We Won’t Cover
- Whether or not these features are considered by best practice.
- These features in both Python 2 and 3 (This site only covers 3).
- Any expenses related to playing Russian Roulette.
while
loops andfor
loops can haveelse
statements!
# RUSSIAN ROULETTE - Let's Play!
# (Seriously, don't.)
chamber_with_bullet = random.randint(1,6)
game_rounds = 3
dead = False
while not dead:
# Spin the chamber, Charles
chamber = random.randint(1,6)
if chamber == chamber_with_bullet:
dead = True
else:
print(f"BLAM: CHAMBER {chamber} IS SAFE!")
game_rounds -= 1
if game_rounds == 0:
# The else block is skipped: you're alive!
print("Congrats, pardner, you're alive!")
break
else:
print(f"BLAM: DEAD.\nThe bullet was in chamber {chamber_with_bullet}.")