我正在 repl.it 中为一个学校项目创建一个 CYOA,并且需要一个列表,所以我所做的就是在每次输入时为用户添加一个选项来查看他们的项目。在主要的分割处我放了
Items = ["Flask of Root Beer"]
print ("Intro:\nYou think to yourself as a 24yo dude with no life ahead of him 'Why am i stuck working in the urban district when I could be in the forest district exploring or something'. With the volcano looming over you, you head out the next morning leaving everything behind you and pursuing your dream of exploration. ")
print ()
print ("You depart from your house with your flask of root beer \nin your pocket and discover a fork in the road. ")
orig_path=input("Do you go left, straight, or right? ")
print ()
if orig_path == "show items" or "items":
print (Items)
if orig_path == "left":
print ("You go to the left and you see a light over in the distance.")
ufo_light=input("Do you investigate? ")
if ufo_light == "show items" or "items":
print (Items)
if ufo_light == ("yes"):
print ("You investigate the bright light and you see that it's a crashed alien ship!")
ufo_four_choice=input("You go into the ship and see that there are four things of note. The console, a alien gun on the floor, some green blood right next to it, and a labeled distress call button. Which one do you investigate first? ")
if ufo_four_choice == "show items" or "items":
print (Items)
if ufo_four_choice == "console" or "the console":
print ("End")
if ufo_four_choice == "alien gun" or "the alien gun":
print ("End")
if ufo_four_choice == "alien blood" or "blood" or "green blood":
print ("End")
if ufo_four_choice == "distress call button" or "button" or "labeled distress call button":
print ("End")
这是我收到的错误https://i.stack.imgur.com/UvOxN.jpg https://i.stack.imgur.com/UvOxN.jpg正如我所说,这是为了学校,所以我只是在学习,所以我没有尝试太多来解决这个问题。我不知道该怎么办,因为我不知道错误是什么。如果您能解释那是什么,我们将不胜感激。
这不是一个真正的错误。这是来自 linter 的警告,告诉您您违反了正确的做法。具体来说,您的代码可以采用太多不同的路径(每个路径有两个)if
)。代码的执行路径越多,理解起来就越困难。
为了解决这个问题,您可以分解该函数并确保所有这些if
s 实际上是必需的。
另请注意,
if ufo_four_choice == "show items" or "items":
类似的线条也被打破了。看here https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)