import random def main(): player1 = 0 player1wins = 0 player2 = 0 player2wins = 0 rounds = 1 while rounds != 10: print("Round " + str(rounds)) player1 = dice_roll() player2 = dice_roll() print("Player 1 Roll: " + str(player1)) print("Player 2 Roll: " + str(player2)) if player1 == player2: print("Draw!\n") elif player1 > player2: player1wins = player1wins + 1 print("Player 1 wins!\n") else: player2wins = player2wins + 1 print("Player 2 wins!\n") rounds = rounds + 1 if player1wins == player2wins: print("Draw!") elif player1wins > player2wins: print("Player 1 Wins - Rounds Won: " + str(player1wins)) else: print("Player 2 Wins - Rounds Won: " + str(player2wins)) def dice_roll(): diceRoll = random.randint(1, 6) return diceRoll main()
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