Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Toss Coin or Dice Throw, or Multi-Sided
- import random
- import time
- def get_choice(prompt, allow):
- while True:
- sin = input(prompt + ": ")
- if sin in allow:
- return sin
- print("Invalid. Try again")
- print("Welcome to the dice game")
- while True:
- print("1. Two-sided Coin")
- print("2. Six-sided Dice")
- print("3. Multi-sided")
- print("9. Quit")
- choice = get_choice("Make your selection from the above", ["1", "2", "3", "9"])
- if choice == "9":
- break
- selection = ["1", "2", "3", "4", "5", "6"]
- if choice == "1":
- selection = ["Heads", "Tails"]
- if choice == "3":
- selection = [str(x) for x in range(1, 21)]
- sides = get_choice("How many numbers do you want?", selection)
- n = int(sides)
- selection = selection[:n]
- random_element = random.choice(selection)
- print("The computer chose:", random_element)
- print(selection)
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement