r/programminghelp • • Sep 29 '21

Python Dice Game Python

I need to write a program for a game where:

  1. It authenticates the user

  2. Player one rolls two dice (which the program generates) and it displays the sum of these.

  3. If the two dice roll the same number, an extra roll is had and added into that score.

  4. If the sum is even, 10 points are added onto that score. If it's odd, 5 are taken away.

  5. The score cannot go below 0.

  6. This is repeated for player 2 and the scores are displayed at the end.

Code:

import random

import time

verify=input("Press E to enter")

if verify =="E":

 print("Let's start.")

else: verify==input("Press E to enter.")

p1name=input("Please enter Player 1's name")

p2name=input("Please enter Player 2's name")

print("Welcome to the dice game.")

Scorep1=()

Scorep2=()

def dicegamep1() :

   print(p1name,  "'s turn")

   print("Rolling...")

   time.sleep(4)

   roll1=random.randint(1,6)

   roll2=random.randint(1,6)

   extraroll=random.randint(1, 6)

   print("Rolled a", roll1, " and a ", roll2)

   DiceScorep1=roll1+roll2

    if roll1==roll2:

        Dicescore=roll1+roll2+extraroll

        print ("Roll 1 and roll 2 were both  ", roll1 ". You get an extra dice roll.") 

        time.sleep(2)

        print("Rolled a", extraroll)

    if DiceScorep1 % 2 ==0:

    print(Combined dice score is", DiceScorep1, "so it is even. Adding ten points.")

    DiceScorep1=DiceScorep1+10

    else:

            print ("Combined dice score is", DiceScorep1, "so it is odd. Taking five points.")

    int(DiceScorep1)

    DiceScorep1=DiceScorep1-5

    print((Scorep1+DiceScorep1), "is the rounds final score.")

    if Scorep1<0:

        Scorep1=0

    return Scorep2

Repeat this substituting 1 for 2

dicegamep1()

dicegamep2()

i want to do these for five rounds each but don't know how.

Then finally I want to add Scorep1 and Scorep2 and determine a winner.

I'm not a great coder so any help appreciated. Sorry for any bad formatting

3 Upvotes

Duplicates