Skip to content

Instantly share code, notes, and snippets.

@alperbayram
Last active April 15, 2024 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alperbayram/2f04e47decacfd59645592125f073627 to your computer and use it in GitHub Desktop.
Save alperbayram/2f04e47decacfd59645592125f073627 to your computer and use it in GitHub Desktop.
import random
total_players = 0
total_rolls = 0
seed = int(input("Please enter a seed value: "))
random.seed(seed)
play_again = 'y'
while play_again == 'y':
total_players += 1
rolls = 0
got_six = False
while not got_six:
rolls += 1
roll = random.randint(1, 6)
print("You rolled a", roll)
if roll == 6:
print("Congratulations! It took you", rolls, "rolls to get a 6.")
total_rolls += rolls
got_six = True
average_rolls = total_rolls / total_players if total_players > 0 else 0
print("Average number of rolls to get a 6:", average_rolls)
valid_input = False
while not valid_input:
play_again = input("Do you want to play again? (y/Y/n/N): ")
if play_again in ['Y', 'y']:
play_again = 'y'
valid_input = True
elif play_again in ['N', 'n']:
play_again = 'n'
valid_input = True
else:
print("Invalid input. Please enter 'y', 'Y' 'n' or 'N'.")
print(total_players, "players have played the game in total. Die has been rolled", total_rolls, "times.")
print("Thank you for playing!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment