from random import randint def game(lenght, printing=True): if printing: print(" ______ ") print(" / /\ ") print(" / ' / \ ") print("/_____/. . \ ") print("\ . . \ . / ") print(" \ . . \ / ") print(" \_____\/ ") print(" ") print("__________________________") print(" ") print(" Člověče nezlob se") print("--------------------------") Player1 = input("Hello, please, enter your name: ") print("Ok", Player1, "You will be Player1 ") Player2 = input("Hello, please, enter your name: ") print("Ok", Player2, "You will be Player2 ") print("-"*20) print(""*20) round = 0 Player1 = 1 Player2 = 1 throw1 = '-' throw2 = '-' while True: if printing: print_game(Player1, Player2, lenght, throw1, throw2, round) round += 1 if printing: print("Player1 Press \'Enter\' to roll the dice.", end='\r') input() throw1 = throw_dice() if printing: print("You rolled a " + str(throw1) + '!') if printing: print("Player2 Press \'Enter\' to roll the dice.", end='\r') input() throw2 = throw_dice() if printing: print("You rolled a " + str(throw2) + '!') print(" ") Player1 += throw1 Player2 += throw2 if Player1 %7 == 0: Player1 -=2 if Player2 %7 == 0: Player2 -=2 if Player1 >= lenght: if printing: print('Congratulations, Player1 won!') print('Round: {};\n'\ ' Player1: {}; dice roll: {};\n'\ ' Player2: {}; dice roll: {}.\n'.format( round, Player1, throw1, Player2, throw2,)) break elif Player2 >= lenght: if printing: print('Congratulations, Player2 won!') print('Round: {};\n'\ ' Player1: {}; dice roll: {};\n'\ ' Player2: {}; dice roll: {}.\n'.format( round, Player1, throw1, Player2, throw2,)) break return round, Player1, Player2 def print_game(Player1, Player2, lenght, throw1, throw2, round): for i in range(1, lenght + 1): if i != Player1: print('-', end='') else: print('*', end='') print() for i in range(1, lenght + 1): if i != Player2: print('-', end='') else: print('#', end='') print() print('Round: {};\n'\ ' Player1: {}; dice roll: {};\n'\ ' Player2: {}; dice roll: {}.\n'.format( round, Player1, throw1, Player2, throw2,)) def throw_dice(): res = randint(1, 6) if res == 6: res = randint(1, 6) return res def game_analysis(lenght, count): avg_round = 0 for i in range(count): result = game(lenght, printing=False) avg_round += result[0] avg_round /= count print('Average number of rounds: {}.\n'.format(avg_round)) game(20) game_analysis(20, 50)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question