在用户键入 'quit' 之前,如何使 if 语句重复出现?

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

我正在 Python 编码。

假设程序启动时,系统会提示用户以下内容:

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.

无论用户输入什么,都会执行 if 语句。我希望这个程序继续运行,直到用户键入退出。尽管如此,作为一个用户,我希望能够按我想要的次数继续点击 1) 或 2)。

到目前为止,这是我的代码:

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 = '9'
    print "You made %s last week." % (money)

if x == 'quit':
    print 'Goodbye

我唯一想让这个程序停止的是如果用户键入 "quit."

我该怎么做?我需要一个由 if 语句组成的 while 循环吗?如果是这样,我该怎么做?

只需将所有内容放在 while True 循环中,然后在用户输入 quit:

时使用 break
while True:
    x = raw_input("Enter number here (or 'quit' to end): ")
    if x == 'quit':
        break

    # ...