 # Python Syntax

def get_algorithm_result(n):
if type(n) == type():
largest = n
for item in n:
if largest < item:
largest = item
return max(n)
else:
pass
return largest

def prime_number(integer):
if integer%3==0 and3!=integer:
return False
else:
return True

the above code didnt work for me and i am stuck
is there anything i’m missing?

I have try the above code yet I still get an error could someone help me out please

guess we are both in the same boat:
can you work around this?
def get_algorithm_result(num_list):
largest =num_list
for item in range(0,len(num_list)):
if largest < num_list[item]:
largest = num_list[item]
return largest

def prime_number(integer):
if integer%2==0:
return False
else:
return True

it didnt run, both my error was reduced, guess i need a way to work around the integer%2==0

You need to define a prime number.

if integer < 2:
return False
elif integer == 2:
return True
else:
for item in range(2, (integer - 1)):
if (integer % item) == 0:
return False
return True

this is my code:
`def get_algorithm_result(num_list):

largest = num_list

for i in range(0, len(num_list)):
if largest < num_list[i]:
largest = num_list[i]
if num_list[i] == num_list[(len(num_list))-1]:
return largest
else:
pass
return largest

def prime_number(integer):
if integer == 1:
return False
elif integer == 2:
return True
if integer > 2:
for i in range(2, (integer-1)):
if integer % i == 0:
return False
else:
return True

This is the unittest

``

But then it still tells me Test Spec Failed Your solution failed to pass all the tests. What did I miss?
This is the code as it appears in the editor

hi,this is what i came up with and i still got Test Spec Failed Your solution failed to pass all the tests. What did I miss?

def get_algorithm_result(num_list):
largest =num_list
for item in range(0,len(num_list)):
if largest < num_list[item]:
largest = num_list[item]
return largest

def prime_number(integer):
if integer%2==0:
return False
else:
return True

how did you do it bro. dis is what i came up with?

this is what i came up with and i still got Test Spec Failed Your solution failed to pass all the tests. What did I miss?

def get_algorithm_result(num_list):
largest =num_list
for item in range(0,len(num_list)):
if largest < num_list[item]:
largest = num_list[item]
return largest
def prime_number(integer):
if integer%2==0:
return False
else:
return True

I still got the Test Spec Failed Your solution failed to pass all the tests. Stuck there for now. Still searching for a solution.

1 Like
``````def prime_number(integer):
if integer == 1:
return False
elif integer == 3:
return True
if integer > 3:
for i in range(3, (integer-1)):
if integer % i == 0:
return False
else:
return True
`indent preformatted text by 4 spaces`
``````

this should now work for you , you only needed to change the 2 to a prime number 3

1 Like

@thebonface,
What happens with `integer` being 0 or 2

hi,the code is working but if i try to test it i get this error.

Total Specs: 5 Total Failures: 1
.

1. test_prime_number_oneFailure in line 19, in test_prime_number_one
self.assertEqual(result, False, msg=“Result is invalid”)
AssertionError: Result is invalid

please what can i do to resolve dis?

I’m still getting an error. Does anyone know what I’m doing wrong?

``````def get_algorithm_result(num_list):
if type(num_list) == type([]):
Largest = num_list
for item in range(0,len(num_list)):
if Largest < num_list[item]:
Largest = num_list[item]
return Largest
else:
return(num_list[-1])``````

i got this after trying the code:

Total Specs: 5 Total Failures: 1
.

1. test_prime_number_oneFailure in line 19, in test_prime_number_one
self.assertEqual(result, False, msg=“Result is invalid”)
AssertionError: Result is invalid

what can i do to correct it?

@codedamn,
You have to be aware that
when you execute the `return` statement
you will directly `exit` the function

Sorry Leonhard, could you please elaborate a little?

``````def get_algorithm_result(num_list):
if type(num_list) == type([]):
Largest = num_list
for item in range(0,len(num_list)):
if Largest < num_list[item]:
Largest = num_list[item]
return Largest

print get_algorithm_result([10,1,12,24,2])``````
1 Like

wow thank you! you also helped me solve another code as well

prime_number(25) is going to return TRUE

1 Like