mercredi 13 mai 2015

Python: If...and... not working as expected

I'm trying to set up the below code to ask the user to enter two integers (num_sides & num_rolls). If the user doesn't enter an integer for either input, then the code should print the statement "Enter an integer".

I find this code only tests the num_sides but doesn't test if num_rolls is an integer. What's going on here?

Thanks in advance for your help!

def rolldice():
    while True:
        while True:
            num_sides = input("Enter number of sides for die: ")
            num_rolls = input("Enter number of rolls for die: ")
            try:
                if int(num_sides) != num_sides or int(num_rolls) != num_rolls:
                    break
                break
            except(ValueError):
                print("Enter an integer")
                True

Aucun commentaire:

Enregistrer un commentaire