-
-
Save alperbayram/2f04e47decacfd59645592125f073627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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