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 s…


This content originally appeared on DEV Community and was authored by Frank Friedland

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()


This content originally appeared on DEV Community and was authored by Frank Friedland


Print Share Comment Cite Upload Translate Updates
APA

Frank Friedland | Sciencx (2022-04-12T22:55:21+00:00) Very much a beginner…. Retrieved from https://www.scien.cx/2022/04/12/very-much-a-beginner/

MLA
" » Very much a beginner…." Frank Friedland | Sciencx - Tuesday April 12, 2022, https://www.scien.cx/2022/04/12/very-much-a-beginner/
HARVARD
Frank Friedland | Sciencx Tuesday April 12, 2022 » Very much a beginner…., viewed ,<https://www.scien.cx/2022/04/12/very-much-a-beginner/>
VANCOUVER
Frank Friedland | Sciencx - » Very much a beginner…. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/12/very-much-a-beginner/
CHICAGO
" » Very much a beginner…." Frank Friedland | Sciencx - Accessed . https://www.scien.cx/2022/04/12/very-much-a-beginner/
IEEE
" » Very much a beginner…." Frank Friedland | Sciencx [Online]. Available: https://www.scien.cx/2022/04/12/very-much-a-beginner/. [Accessed: ]
rf:citation
» Very much a beginner… | Frank Friedland | Sciencx | https://www.scien.cx/2022/04/12/very-much-a-beginner/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.