-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBVV_ISaP-13_PW-35.1.py
53 lines (41 loc) · 1.29 KB
/
BVV_ISaP-13_PW-35.1.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
52
53
#14 Version
#First Problem
def count_divisors(num):
count = 0
if num < 0:
num = num - num*2
#print("Num: "+str(num))
for i in range(1, num+1):
if num % i == 0:
#print(i)
count += 1
return count;
startIntervalNum = None;
endIntervalNum = None;
numWithMostDivisors = 0;
numsWithMostDivisors = [numWithMostDivisors];
while startIntervalNum == None:
try:
startIntervalNum = int(input("Enter start interval num: "))
except:
print("\nUncorrect value!")
while endIntervalNum == None:
try:
endIntervalNum = int(input("Enter end interval num: "))
if endIntervalNum < startIntervalNum:
endIntervalNum = None
raise;
except:
print("\nUncorrect value!")
for i in range(startIntervalNum, endIntervalNum+1, 1):
divisors = count_divisors(i)
if divisors > count_divisors(numWithMostDivisors):
numWithMostDivisors = i
numsWithMostDivisors = [i]
elif divisors == count_divisors(numWithMostDivisors):
numsWithMostDivisors = numsWithMostDivisors + [i]
print(f'''
\nNumbers with most natural divisors = {numsWithMostDivisors}
Count of divisors num in range {startIntervalNum} - {endIntervalNum} = {count_divisors(numWithMostDivisors)}
\n''')
input()