jeudi 21 janvier 2016

Using if else statement to assign a variable in python

I'm trying to make a program telling you how to order a specific number of nuggets, using if and else statements to assign variables. My problem is if one of the first if statements is true, then the program throws an error, because I called a variable that doesn't exist. How can I make My program skip over the rest of the if/else statements if the first one is found to be true?

nuggets = input("How many nuggets do you need? ")

nuggets = int(nuggets)

nuggets20 = nuggets % 20


if nuggets20 == 0:
    n20 = True

else: 
     nuggets10 = nuggets20 % 10

if nuggets10 == 0:
    print(nuggets10)

else: 
    nuggets6 = nuggets10 % 6

if nuggets6 == 0:
    print(nuggets6)

else:
    nuggets4 = nuggets6 % 4



if n20 == True:
    print("nuggets")

Aucun commentaire:

Enregistrer un commentaire