0

I am trying to make a dice rolling game. I want to generate a random integer in the range of the number of dice I have multiplied by the number of sides the dice has. For example, if two dice were played with three sides, then there could be any number between 2 and 6.

Here is my code; when I put in, for example one dice and two sides, it prints numbers upwards of 13. The problem is that it doesn't create an integer between the amount of sides and dice.

condition = "Start" 
while condition == "Start": 
Dice = int(input("Please select number of dice you would like to use (atleast 1)"))
Sides = int(input("Please select number of sides on dice you would like to use (atleast 2)"))
if Dice <= 0 and Sides <= 1:
    condition = "Start"
elif Dice >= 1 and Sides >= 2:
    print("You have selected", Dice," dice and", Sides,"Sides")
    condition = "play" 
    Roll1 = 0
    Roll2 = 0 
    Score1 = 0 
    Score2 = 0
while condition == "play": 
        Roll1 += randint(Dice,Sides)
        Roll2 += randint(Dice,Sides)
        print (name1,"'s Roll", Roll1) 
        print (name2,"'s Roll", Roll2)
Engineer
  • 29,455
  • 4
  • 72
  • 120

1 Answers1

2

You seem to be missing a loop to simulate the number of dice there are to roll, and you seem to be using the randint function incorrectly.

I haven't tested this code but it should get you started:

condition = "Start" 
while condition == "Start": 
    Dice = int(input("Please select number of dice you would like to use (atleast 1)")) 
    Sides = int(input("Please select number of sides on dice you would like to use (atleast 2)")) 
    if Dice <= 0 and Sides <= 1:
        condition = "Start"
    elif Dice >= 1 and Sides >= 2:
        print("You have selected", Dice," dice and", Sides,"Sides")
        score = 0
        for i in range(Dice):
            roll = randint(1,Sides)
            score += roll
            print ("Die # ", i + 1, "'s Roll :", roll)
        print ("Score: ", score)

Basically, the for loop there will iterate over the number of dice roll that the user expected. With that, you don't need to create a variable for each roll.

And the randint method needs the min and max values. In the code you provided, you are mixing apples and oranges; Dice and Sides are not really related. What you want is the minimum value of one (the minimum value will be one for any dice), and the max value, as you could see, is the Sides variable, as you used.

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61