Advertisement
acclivity

pyChance

Feb 3rd, 2021
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. # Toss Coin or Dice Throw, or Multi-Sided
  2. import random
  3. import time
  4.  
  5.  
  6. def get_choice(prompt, allow):
  7.     while True:
  8.         sin = input(prompt + ": ")
  9.         if sin in allow:
  10.             return sin
  11.         print("Invalid. Try again")
  12.  
  13.  
  14. print("Welcome to the dice game")
  15.  
  16. while True:
  17.     print("1. Two-sided Coin")
  18.     print("2. Six-sided Dice")
  19.     print("3. Multi-sided")
  20.     print("9. Quit")
  21.     choice = get_choice("Make your selection from the above", ["1", "2", "3", "9"])
  22.     if choice == "9":
  23.         break
  24.     selection = ["1", "2", "3", "4", "5", "6"]
  25.     if choice == "1":
  26.         selection = ["Heads", "Tails"]
  27.     if choice == "3":
  28.         selection = [str(x) for x in range(1, 21)]
  29.         sides = get_choice("How many numbers do you want?", selection)
  30.         n = int(sides)
  31.         selection = selection[:n]
  32.  
  33.     random_element = random.choice(selection)
  34.     print("The computer chose:", random_element)
  35.     print(selection)
  36.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement