gpt4 book ai didi

python - if 语句中的 if 语句

转载 作者:太空宇宙 更新时间:2023-11-04 10:09:56 26 4
gpt4 key购买 nike

这是我的功课,我坚持让代码成为后续问题,就像这里的这段代码,我试过在那之后插入一个 if 语句,但它给了我一个意外的激励错误。

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

Choice = input("Hello! Do you want to buy or sell snakes? Please enter (b) or (s) :")
if Choice == "b":
buySnake = input ("What snake do you want to buy? We are selling python, kingsnake, rattlesnake, deathadder, cobra, mamba, viper and gartersnake. Please choose one : ")
if buySnake == "python":
return (to be added)
elif Choice == "s":
sellFsnakes(snakeList,name,amount)
else:
print("Please try again.")
buyWsnakes(snakeList,name,amount)

最佳答案

你有一个额外的缩进。只需删除额外的缩进级别:

Choice = input("Hello! Do you want to buy or sell snakes? Please enter (b) or (s) :")
if Choice == "b":
buySnake = input ("What snake do you want to buy? We are selling python, kingsnake, rattlesnake, deathadder, cobra, mamba, viper and gartersnake. Please choose one : ")
if buySnake == "python":
return (to be added)
elif Choice == "s":
sellFsnakes(snakeList,name,amount)
else:
print("Please try again.")
buyWsnakes(snakeList,name,amount)

关于python - if 语句中的 if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38987390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com