DEV Community

Frank Friedland
Frank Friedland

Posted on

Very much a beginner...

Just found this community and I'm glad I did! Like my title says, very much a beginner, but my end goal for Python is to upskill and utilize it for network automation.

I tackled a simple dice roller today that takes user input to determine how many sides and how many dice to roll.

Going to add in an error if the user inputs letters into the dice side/number inputs as well as make the "yes" answer more inclusive of capitalization. Please feel free to tear it apart or give me ideas on anything I can add!

import random

# Determine a random side for each number rolled
def rollDice():

# Get how many sides a dice has
    print("How many sides does the dice have?" )
    diceSideNum = input()

# Get number of those dice to role
    print("How many " + diceSideNum + " sided dice should we roll? ")
    diceNum = input()

# incr variable to increment by 1 to roll correct amount of dice
    incr = 0

# while incr doesn't equal number of dice rolled, iterate.
    while int(incr) != int(diceNum):
# random dice number is between 1 and the # chosen by the user
        num = random.randrange(1, int(diceSideNum))
# Side of the dice randomly chosen and printed to display
        print(num)
# test incremented by 1
        test += 1
# reroll() asks essentially to play again.
    reroll()

def reroll():
    reroll = input("Roll again? ")
    if reroll == "yes":
        rollDice()
    else:
        print("Good-bye")

rollDice()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)