我正在为我正在编写的一个小程序编写一部分代码。记住我对此很新。python3循环问题
继承人的代码:
def sell():
sell = input("\nGreetings! What would you like to do today?\nPress 1 to sell an animal\nPress 2 to buy an animal\nPress 3 If you want to see all the farms and their animals first\n")
if sell == "1":
whichs = input("Which animal do you want to sell?\nPress 1 for pig\nPress 2 for horse\nPress 3 for cow\nPress 4 for bull\n")
if whichs == "1":
print ("\nYou just sold\n",p[0])
print ("\nYou now have 350gold")
print ("\nThese are the animals you have left:")
print (p[1], p[2], p[3]) #Prints the animals you have left from p list.
elif whichs == "2":
print ("\nYou just sold\n",p[1])
print ("\nYou now have 350gold")
print ("\nThese are the animals you have left:")
print (p[0], p[2], p[3])
elif whichs == "3":
print ("\nYou just sold\n",p[2])
print ("\nYou now have 360gold.")
print ("\nThese are the animals you have left:")
print (p[0], p[1], p[3])
elif whichs == "4":
print ("\nYou just sold\n",p[3])
print ("\nYou now have 350gold.")
print ("\nThese are the animals you have left:")
print (p[0], p[1], p[2])
else:
print ("Error")
我想这个循环因此当用户已经卖出一只动物,他们开始了与:
sell = input("\nGreetings! What would you like to do today?\nPress 1 to sell an animal\nPress 2 to buy an animal\nPress 3 If you want to see all the farms and their animals first\n")
我正与如何struggeling已经完成了。
你试过'while'语句吗? –
这里是[参考](http://docs.python.org/2/reference/compound_stmts.html#while)。这里是一个[教程](http://www.tutorialspoint.com/python/python_while_loop.htm)。 –