jeudi 13 octobre 2016

How to detect when a maximum number is rolled?

This question seems like it would be easily answered by just making an if statement for my maximum in the range, BUT please take a second to read before calling me an idiot. I am making a program that lets the user choose between many different dice. I am wondering if there is an easy way to detect when the maximum value is rolled from any of the options without setting if statements for all of the different dice.

def inphandle(choice):
    if choice==4:
        roll = random.randint(1,4)
    elif choice==6:
        roll = random.randint(1,6)
    elif choice==8:
        roll = random.randint(1,8)
    elif choice==10:
        roll = random.randint(1,10)
    elif choice==20:
        roll = random.randint(1,20)
    return roll

def dice(roll):
    min = 0
    if roll==1:
        print("Min roll! Try again!")
        min = min+1
    if roll 


def mainmenu():
    print("Please choose from the following options:")
    print("Roll | EXIT")
    option = input()
    if option=="EXIT" or option=="exit" or option=="Exit"
        print("You rolled" + max + "max rolls and " + min + " min rolls! Goodbye!")

def main():
    choice = int(input("Please enter a number corresponding to the number of faces on your dice. E.x. 4 for 4-Sided: "))
    cont = input("Would you like to roll the dice? Y or N: ")
    while cont=="y" or cont=="Y":
        roll = inphandle(choice)
        dice(roll)
        cont = input("Would you like to roll again? Y or N: ")
    while cont=="n" or cont=="N":
        easteregg()
        cont = input("Do I get bunus points now?!?")
main()

I do have random imported, but this is simply a section of the whole program. I understand if there is no shortcut to this, but I wanted to check before typing it all out since it might not be necessary.




Aucun commentaire:

Enregistrer un commentaire