Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 12, 2022 10:55 pm GMT

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

Original Link: https://dev.to/onthefritz/very-much-a-beginner-15ph

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To