我正在为我正在编写的一个小程序的一部分代码苦苦挣扎。请记住,我对此很陌生。
继承人的代码:
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")
我正在为如何做到这一点而苦苦挣扎。