-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coprime
50 lines (35 loc) · 1.49 KB
/
Coprime
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
## Name: Jaewon Son
## Date: September 10 2023
## Honor Statement: I have not given or received any unauthorized assistance on this assignment.
## Link: https://youtu.be/XnlSa-IstYY
def coprime(coprime_test_number1, coprime_test_number2):
"""Function for checking whether two numbers are coprime or not.
Args:
coprime_test_number1 (int): Natural number typed by a prompt in the first order.
coprime_test_number2 (int): Natural number typed by a prompt in the second order.
Returns:
bool: Returns true when the numbers are coprime and returns false when the numbers are not coprime.
"""
if coprime_test_number1 == 1 or coprime_test_number2 == 1:
return True
else:
count = 0
if coprime_test_number1 < coprime_test_number2:
for i in range(2, coprime_test_number1 + 1):
if coprime_test_number1 % i == 0 and coprime_test_number2 % i == 0:
count += 1
else:
for i in range(2, coprime_test_number2 + 1):
if coprime_test_number2 % i == 0 and coprime_test_number1 % i == 0:
count += 1
return count < 1
while True:
coprime_test_number1 = input('Enter the First Number or Exit: ')
if coprime_test_number1 == 'Exit':
print('Thank you for using Coprime test!')
break
coprime_test_number2 = input('Enter the Second Number: ')
if coprime(eval(coprime_test_number1), eval(coprime_test_number2)):
print('Those two numbers are coprime.')
else:
print('Those two numbers are not coprime.')