'I am trying to create a dice roller that i can adjust how many dice are rolled and adjust how many numbers it outputs based on that
As mentioned in the title I'm in the proses of creating a dice roller that lets the user decide how many dice they want to roll without limiting the amount of dice so far I've gotten it to a stage where it can roll the dice then print the results of one of the dice but I can't figure out how to get it to display multiple rolls I was thinking of getting the code to create variables for the outputs and print them all but I have no clue if this it possible or not
import sys
h = 0
r = input('Would you like to roll the dice [y/n]?\n')
while r != 'n':
if r == 'y':
m = input('What do you want to be able to role up to\n')
t = input('How many times do you want to want to roll the dice\n')
for h in range(int(t)):
d = random.randint(1, int(m))
h = h+1
print(d)
question = input('Would you like to roll the dice [y/n]?\n')
else:
print('Invalid response. Please type "y" or "n".')
question = input('Would you like to roll the dice [y/n]?\n')
print('Good-bye!')
Any help would be greatly appreciated
Solution 1:[1]
As mentioned in the comments, move print(d) inside the loop and you will have what you want. Moreover h = h+1 is totally useles, since the iteration of the for loop is automatic.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rikyeah |
