-
Notifications
You must be signed in to change notification settings - Fork 0
/
a05.py
51 lines (38 loc) · 1.02 KB
/
a05.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
## IMPORTS GO HERE
## END OF IMPORTS
#### YOUR CODE FOR is_prime() FUNCTION GOES HERE ####
def is_prime(x):
x=abs(int(x))
if x < 2:
return False
if x % 2 == 0:
return False
if x > 2:
n = x // 2
for i in range(2, n + 1):
if x % i == 0:
return False
return True
#### End OF MARKER
#### YOUR CODE FOR output_factors() FUNCTION GOES HERE ####
def output_factors(h):
p=0
while p<h:
p=p+1
if h%p==0:
print p
#### End OF MARKER
#### YOUR CODE FOR get_largest_prime() FUNCTION GOES HERE ####
def get_largest_prime(n):
lorgest = 0
n=int(n)
for i in range (n+1):
if is_prime(i):
largest = i
return largest
#### End OF MARKER
if __name__ == '__main__':
print is_prime(499) # should return True
print get_largest_prime(10) # should return 7
# print get_largest_prime(100000) # bonus, try with 100k
output_factors(10) # should output -- 1 2 5 10 -- one on each line