# Untitled

unknown
plain_text
a year ago
2.1 kB
0
Indexable
Never
```import random

def play_game():
num_dice = int(input("How many dice do you want to play with? "))
num_faces = int(input("How many faces do your dice have? "))
players = []
num_players = int(input("How many players are playing? "))
for i in range(num_players):
name = input(f"Enter the name of player {i+1}: ")
players.append({"name": name, "dice": num_dice})
current_player = random.randint(0, num_players-1)
last_bid = (0, 0)
while True:
print(f"{players[current_player]['name']}'s turn:")
bid = input(f"Enter your bid (quantity face), or type 'challenge': ")
if bid.lower() == 'challenge':
total = 0
for player in players:
for die in range(player['dice']):
face = random.randint(1, num_faces)
if face == last_bid[1]:
total += 1
if total >= last_bid[0]:
print(f"{players[current_player]['name']} wins!")
break
else:
players[current_player]['dice'] -= 1
if players[current_player]['dice'] == 0:
print(f"{players[current_player]['name']} is out of the game!")
players.remove(players[current_player])
num_players -= 1
if num_players == 1:
print(f"{players[0]['name']} wins!")
break
print(f"{players[current_player]['name']} loses a die!")
current_player = (current_player + 1) % num_players
last_bid = (0, 0)
else:
try:
quantity, face = map(int, bid.split())
if (quantity > last_bid[0]) or (quantity == last_bid[0] and face > last_bid[1]):
last_bid = (quantity, face)
current_player = (current_player + 1) % num_players
else:
print("Your bid must be higher than the last bid!")
except:
print("Invalid input!")

play_game()```