ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Other languages

Python Dice game

Submitted by HappyHacker at 06-02-2023, 07:19 AM


Python Dice game
4.325 Views
HappyHacker's Avatar'
HappyHacker
Offline
#1
[ Hidden Content! ]

import random

player1 = input("What is your name: ")
player2 = input("What is your name: ")

player1_score = 0
player2_score = 0

# Repeat everything in this block 10 times
for i in range(5):

    # Generate random numbers between 1 and 6 for each player.
    player1_value = random.randint(1, 6)
    player2_value = random.randint(1, 6)

    # Display the values
    print("Player 1 rolled: ", player1_value)
    print("Player 2 rolled: ", player2_value)

    # Selection: based on comparison of the values, take the appropriate path through the code.
    if player1_value > player2_value:
        print("player 1 wins.")
        player1_score = player1_score + 1  # This is how we increment a variable
    elif player2_value > player1_value:
        print("player 2 wins")
        player2_score = player2_score + 1
    else:
        print("It's a draw")

    input("Press enter to continue.")  # Wait for user input to proceed.

print("### Game Over ###")
print(player1 + ":", player1_score)
print(player2 + ":", player2_score)
if player1_score > player2_score:
    print(player1+ " wins. ")
else:
    print(player2 + " wins. ")

0
Reply


Messages In This Thread
Python Dice game - by HappyHacker - 06-02-2023, 07:19 AM
RE: Python Dice game - by Gundhram - 04-10-2023, 12:46 PM
RE: Python Dice game - by abhiiii_099 - 10-01-2024, 10:56 AM
RE: Python Dice game - by Abhikashyap99 - 10-01-2024, 11:17 AM
RE: Python Dice game - by Deadgod1828 - 25-09-2024, 11:22 PM
RE: Python Dice game - by nigganigga1111 - 31-01-2025, 06:54 PM
RE: Python Dice game - by snow1122 - 01-02-2025, 02:42 AM


Users browsing this thread: 1 Guest(s)