Ask coding questions

← Back to all posts
Cyclomatic Complexity too high?
OwenBradstreet (124)

I know that Cyclomatic Complexity is the number of different routes the user can take through code after a certain point (correct me if I'm wrong), but how can it be too high? Python 3 says above 15 is too high - it doesn't seem to affect my code in any way, it's just annoying that it underlines code for no apparent reason.

Can someone explain this to me? Thanks.

amasad (3355)

Do you have an example? 15 does seem too high though (that means ~15 nested blocks?)

OwenBradstreet (124)

@amasad I don't have an example that wouldn't fill a page haha, but 15 or more nested if's yes (not all under one if statement, nested within eachother). Why is 15 too high though? As in, what disadvantage or issues does it cause?

MatthewAllison1 (4)

import colorama as cr

print("MOS Kern v1.4 Beta, \n by MI Software \n(c) 2019 Matthew_ink.")
usr_load = open("Users", "r")
usr_read =
usr_try = input("Username: ")
while usr_try != usr_read:
usr_try = input("Username: ")
if usr_try == usr_read:
pass_load = open("Password", "r")
pass_read =
pass_try = input("Password: ")
while pass_try != pass_read:
pass_try = input("Password: ")
if pass_try == pass_read:
print(f"{cr.Fore.GREEN}\nCorrect.{cr.Fore.YELLOW}\nUse the command \"help\" for a list of commands.")
#-----Main Loop-----#
while True:
command = input(">> ")
if command == "help":
print(f"{cr.Fore.GREEN}The commands are:\ntxt\n txt edit\n txt view\nhelp\ncalc")
if command == "txt view":
print(f"{cr.Fore.RED}NOTE: Do not try to create files with txt view!")
file_ask_read = input("File name to open: ")
file_load_read = open("%s" % file_ask_read, "a")
file_load_read = open("%s" % file_ask_read, "r")
file_read =
print(f"{cr.Fore.YELLOW}\n" + file_read)
if command == "txt edit":
file_ask_write = input("File name to edit/create: ")
file_load_write = open("%s" % file_ask_write, "a")
file_load_read = open("%s" % file_ask_write, "r")
file_read =
file_ask_write = input(file_read)
file_load_write.write(f"{cr.Fore.YELLOW}\n" + file_ask_write)
if command == "txt":
print(f"{cr.Fore.RED}ERROR: Missing Argument \"Open type\" \n {cr.Fore.YELLOW}Syntax: txt <view><edit>")
if command == "calc":
x = input()
o = input(x)
y = input(x + o)
if o == "+":
z = float(x) + float(y)
if o == "-":
z = float(x) + float(y)
if o == "/":
z = float(x) / float(y)
if o == "
z = float(x) * float(y)
if o == "^":
z = float(x) ^ float(y)

It gave me it on line 13.

Macknificent101 (0)

this makes my HS student mind hurt... @MatthewAllison1

SeamusDonahue (439)

for me it starts on line 314 of my program where I reset a variable to ensure that the next while loop will trigger (this is nested in a while loop). it says my complexity is 89. I don't doubt that but does it matter?