[McCabe]环境复杂性太高的误差意味着什么



我在repl.中创建一个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正如我说的那样,我只是在学习,所以我没有尝试过太多解决此问题。我不知道该怎么办,因为我不知道该错误是什么。如果您能解释一下,这将不胜感激。

这不是实际错误。这是林格的警告,告诉您您违反了适当的实践。具体来说,您的代码具有太多不同的路径(每个if(。您的代码的执行途径越多,就越难以理解。

为了解决这个问题,您可以打破功能并确保实际需要所有这些ifS。


也请注意,

if ufo_four_choice == "show items" or "items":

和类似的行被打破。请参阅此处。

循环复杂性是基于程序中的"路径数"的"复杂"软件的量度。通常,我认为这是对有条件分支的量度。

循环复杂性

有一个更完整的写入

此错误意味着您的程序具有太多的代码块,例如。循环,def,类(如果/else and try/deve/deve/def(中的标签或空格。尝试减少它们的量,如果可能的话,请使用技巧或数据结构。

最新更新