mercredi 25 mars 2015

How can I make if-statements recurring until the user types 'quit'?

I am coding in Python.


Let us say when the program starts, the user is prompted with the following:



Press 1) to check what the temperature is outside.
Press 2) to find out how many miles are on your car.
Press 3) to see how full your gas tank is.
Press 4) to find out how much money you made last week.


Whatever the user types in, the if statement is executed. I want this program to keep going until the user types quit. Nonetheless, as a user, I want to be able to keep hitting 1) or 2) as many times as I want.


Here is my code thus far:



x = raw_input("Enter number here: ")

if x == '1':
weather = 46
print "%s degrees" % (weather)

if x == '2':
milesoncar = '30,000'
print "%s miles" % (milesoncar)

if x == '3':
gasintank = 247.65
print "%s miles left in gas tank" % (gasintank)

if x == '4':
money = '$439'
print "You made %s last week." % (money)

if x == 'quit':
print 'Goodbye


The only thing that I want to make this program stop is if the user types "quit."


How would I go about doing this? Do I need a while loop comprised of if statements? If so, how would I go about doing that?


Aucun commentaire:

Enregistrer un commentaire