How do i implement these algorithms below

Is what you mean with the first one find the largest number? Then you should use max() like

list = [1,2,4,5,3]
print max(list)
>>> 5

This should help with the second one:

def prime_number(n):

    if n > 1:
       for x in range(2,n):
           if (n % x) == 0:
               return False
               break
       else:
           return True

If a number is prime, then the factors are only 1 and itself. If there is any other factor from 2 to the number, it is not prime. n % x finds the remainder when n is divided by x. If x is a factor of n, then n % x has a remainder of 0.

Browse More Popular Posts

Leave a Comment