[Solved] What does a [mccabe] Cyclomatic complexity too high error mean?

I am creating a CYOA in repl.it for a school project and need to have a list so what I did is at every input I am putting an option for the user to see their items. At the main split I put

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")

This is the error I am getting
https://imgur.com/Znk0rLx
As I said this is for school so I am just learning, so I haven’t tried much to fix this. I don’t know what to do because I don’t know what that error is.

if you can explain what that would be it would be greatly appreciated.

Solution #1:

That’s not an actual error. It’s a warning from a linter telling you that you’re in violation of proper practice. Specifically, your code has too many different paths that it can take (two for each if). The more paths of execution your code has, the harder it can be to understand.

To address this, you could break the function up and ensure that all those ifs are actually required.


Also note,

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

And similar lines are broken. See here.

Respondent: Carcigenicate
Solution #2:

Cyclomatic complexity is a measure of how “complex” a piece of software is, based on the “number of paths” through the program. Generally, I think of it as being a measure of how many conditional branches there are.

There’s a more complete write up at Cyclomatic complexity

Respondent: ditch182
Solution #3:

This error means that your program has too many blocks of code, e.g. tabs or spaces in loops, defs, classes, if/else and try/except. Try to reduce the amount of them, use tricks or data structures if possible.

Respondent: Pythonista
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.