我正在为一个学校项目在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://imgur.com/Znk0rLx 正如我所说的,这是上学的,所以我只是在学习,所以我没有做太多的尝试来解决这个问题。我不知道该怎么办,因为我不知道该错误是什么。如果您能解释会是什么,将不胜感激。
答案 0 :(得分:0)
这不是实际错误。这是一则短毛绒警告,告诉您您违反了正确的做法。具体来说,您的代码具有许多不同的路径(每个if
都有两个)。执行代码的路径越多,越难理解。
如果要解决的是,可以分解功能,并确保实际上所有这些if
都是必需的。
还请注意
if ufo_four_choice == "show items" or "items":
并且类似的行也折断了。参见here。
答案 1 :(得分:0)
循环复杂度是基于程序的“路径数”来衡量软件的“复杂度”的度量。通常,我认为它是对有多少条件分支的度量。
在Cyclomatic complexity上有更完整的文章
答案 2 :(得分:0)
这个错误意味着你的程序有太多的代码块,例如循环、定义、类、if/else 和 try/except 中的制表符或空格。尽量减少它们的数量,如果可能的话,使用技巧或数据结构。