Ask coding questions

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

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.

Commentshotnewtop
amasad (2386)

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

OwenBradstreet (94)

@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?

ainain074 (1)

mine is 44 tho -_-

MatthewAllison1 (2)

import colorama as cr
cr.init(autoreset=True)

print("MOS Kern v1.4 Beta, \n by MI Software \n(c) 2019 Matthew_ink.")
usr_load = open("Users", "r")
usr_read = usr_load.read()
#-------------------Login-----------------------------#
usr_try = input("Username: ")
while usr_try != usr_read:
print(f"{cr.Fore.RED}\nIncorrect.")
usr_try = input("Username: ")
if usr_try == usr_read:
print(f"{cr.Fore.GREEN}\nCorrect.")
pass_load = open("Password", "r")
pass_read = pass_load.read()
pass_try = input("Password: ")
while pass_try != pass_read:
print(f"{cr.Fore.RED}\nIncorrect.")
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.close()
file_load_read = open("%s" % file_ask_read, "r")
file_read = file_load_read.read()
print(f"{cr.Fore.GREEN}Loaded!")
print(f"{cr.Fore.YELLOW}\n" + file_read)
file_load_read.close()
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")
print(f"{cr.Fore.GREEN}Loaded!")
file_read = file_load_read.read()
file_load_read.close()
file_ask_write = input(file_read)
file_load_write.write(f"{cr.Fore.YELLOW}\n" + file_ask_write)
file_load_write.close()
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)
print(z)

It gave me it on line 13.