I'm trying to make a dice rolling program in python that rolls dice given the users input on sides, dice, and rolls. Currently this code more or less works, but the problem I'm running into is say I give 3 dice being rolled 3 times with 6 sides to them.
The code I have displays this as the output:
Roll #1 6
Roll #2 5
Roll #3 1
Roll #4 6
Roll #5 4
Roll #6 6
Roll #7 3
Roll #8 1
Roll #9 1
When I need it to display as:
Roll #1 6 5 1
Roll #2 6 4 6
Roll #3 3 1 1
Here's my code so far. My guess is that it has to do something with my arguments and parameters being empty? I'm not entirely sure. Here is my code:
import random
def main ():
rolls = get_rolls()
dice = get_dice()
sides = get_sides()
nrolls = 1
for r in range (rolls):
for d in range (dice):
print ('Roll #', nrolls, random.randint(1,sides))
nrolls += 1
def get_rolls():
rolls = int(input('Enter the number of rolls: '))
while rolls <= 0:
print ('Number of rolls must be higher than 0')
rolls = int (input('Enter the number of rolls: '))
return rolls
def get_dice():
dice = int (input('Enter the number of dice being rolled: '))
while dice < 1 or 5 < dice:
print ('Number of dice being rolled must be between 1 and 5')
dice = int (input('Enter the number of dice being rolled: '))
return dice ()
def get_sides():
sides = int (input('Enter the number of sides on the dice: '))
while sides < 2 or 36 < sides:
print ('Number of sides on dice must be between 2 and 36')
sides = int (input('Enter the number of sides on the dice: '))
return sides
main()