模仿 "Craigslist Program" - 如何将结果与输入分开?

Making an immitation "Craigslist Program" - how can I seperate results from inputs?

我正在写一个模仿craigslist的项目。我需要询问用户是否要: 1. 输入产品 2.购买产品

当用户键入 1 时,系统会询问他们是否要出售 (b)ike 或 (t)ruck,他们提供输入,然后询问价格。 我使用 append 将其添加到列表中。

但是,如果用户输入“2”来工作,我无法获得输入, 如果用户键入“2”而是询问他们是否想出售 (b)ike 或 (t)ruck,它完全无视我要求它打印的内容。

看看我的代码:

play = True
productList =[['bike', 50]] #supposed to be a bike on the list already

print "Would you like to:" 
print "1. Add an item."
print "2. Find an item."

choice = raw_input ("Enter your selection")

while play: 
    if choice == "1":
    play = True
    print "What would you like to sell, a bike or truck?"
    item = raw_input ("enter the item type, b or t.)

    elif item == "b":
        price = raw_input ("enter item cost:")
        bikePrice = "bike" ,price
        productList.append (bikePrice)
        print "Your product has been added to Craigslist"
    elif item == "t":
        price = raw_input ("enter item cost:"
        bikePrice = "bike" ,price
        productList.append (bikePrice)
        print "Your product has been added to Craigslist"

if choice == "2":
    play = True 
    print "yay"

所以本质上,该程序完全忽略了当我键入“2”时它应该打印 yay 的事实。如果用户键入 (1),如何让我的程序仅显示 "Enter a item" (1) 的选项,如果用户键入 (2),则仅显示 "Find an item" (2) 的选项?

我知道有一个简单的解决方法,但我已经写了两个星期的代码而且非常无能:) 谢谢!

为了得到它,我做了一些清理工作 运行。请注意我将 play 设置为 False 的位置,这样您就不会出现无限循环。

play = True
productList =[['bike', 50]] #supposed to be a bike on the list already

print "Would you like to:" 
print "1. Add an item."
print "2. Find an item."

choice = raw_input ("Enter your selection")

while play: 
    if choice == "1":
        play = False
        print "What would you like to sell, a bike or truck?"
        item = raw_input ("enter the item type, b or t.")
        if item == "b":
            price = raw_input ("enter item cost:")
            bikePrice = ["bike", price]
            productList.append(bikePrice)
            print "Your product has been added to Craigslist"
        elif item == "t":
            price = raw_input ("enter item cost:")
            truckPrice = "truck", price
            productList.append(truckPrice)
            print "Your product has been added to Craigslist"
    if choice == "2":
        play = False 
        print "yay"