I have the following problem:
Write the largest_primo function that receives an integer greater than or equal to 2 as a parameter and returns the largest prime number less than or equal to the number passed to the
Note that
largest_primo (100) should return 97
largest_primo (7) should return 7
Tip : write a function ePrimo (k) and make a loop by traversing the numbers to the given number by checking whether the number is prime or not; if it is, save to a variable. At the end of the loop, the value stored in the variable is the largest prime found.
My solution would be:
def éPrimo (k):
div = 2
while k % div != 0 and div <= k:
div = div + 1
if k % div == 0:
k = k - 1
else:
print (k)
I am very convinced that I am right, I am still at a very beginner level and if anyone can give me a light on these basic parameters would be of great help.