Categories
Coding Python Secrets TheMoreYouKnow

The Arcane Secrets Of – PYTHON

Updated 10/13/2020

What We’ll Cover

  1. Various features in Python you may not have known about!
  2. These various features in action!
  3. Russian Roulette!

What We Won’t Cover

  1. Whether or not these features are considered by best practice.
  2. These features in both Python 2 and 3 (This site only covers 3).
  3. Any expenses related to playing Russian Roulette.
  • while loops and for loops can have else 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}.")

Leave a Reply

Your email address will not be published. Required fields are marked *