For my code, I am trying to find the number of times 4 or 5 occurs in each of the three lists, then printing out the maximum value of the most number of times 4 or 5 occurs.
For example, 4 or 5 occurs in the list AAAAA 8 times, also 8 times for BBB and 5 times for K. So the last line of the code should print 8, but I get an error shown below my code as shown.
Note: I have to make this code using functions with parameters in them. I am familiar with lists, strings, for loops, and some other stuff. So don't show me new stuff cause I'm a beginner.
Code:
AAAAA = [4, 2, 1, 2, 4, 2, 4, 4, 5, 2, 2, 1, 5, 2, 4, 3, 1, 1, 3, 3, 5]
BBB = [5, 2, 1, 2, 4, 5, 4, 4, 1, 2, 2, 2, 4, 4, 4, 3, 1, 2, 3, 3, 2]
K = [4, 1, 2, 1, 2, 1, 2, 5, 1, 1, 1, 1, 4, 2, 2, 1, 5, 1, 3, 4, 1]
x = 4
y = 5
def four_or_five(AAAAA, x):
count = 0
for ele in AAAAA:
if (ele == x):
count = count + 1
return count
def four_or_five(AAAAA, y):
count = 0
for ele in AAAAA:
if (ele == y):
count = count + 1
return count
res = print(four_or_five(AAAAA, x) + four_or_five(AAAAA, y)) ### 4 and 5's in list AAAAA
def four_or_five(BBB, x):
count = 0
for ele in BBB:
if (ele == x):
count = count + 1
return count
def four_or_five(BBB, y):
count = 0
for ele in BBB:
if (ele == y):
count = count + 1
return count
res1 = print(four_or_five(BBB, x)+four_or_five(BBB, y)) ### 4 and 5's in list BBB
def four_or_five(K, x):
count = 0
for ele in K:
if (ele == x):
count = count + 1
return count
def four_or_five(K, y):
count = 0
for ele in K:
if (ele == y):
count = count + 1
return count
res2 = print(four_or_five(K, x)+four_or_five(K, y)) ### 4 and 5's in list K
max_res = max(res,res1,res2) ### Find the max number of times 4 and 5 occurs, which is 8
print(max_res)
_____________________________________________________________
OUTPUT:
8
8
5
TypeError: '>' not supported between instances of 'NoneType' and 'NoneType'
Note: Do not worry about certain digits occuring, 4 or 5 is supposed to be fixed so just leave it as 4 or 5. Also when I say don't alter my code's format, I mean as in leave it as defined functions with parameters in them.