forked from mrayanasim09/python-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber_details.py
62 lines (51 loc) · 1.34 KB
/
number_details.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
54
55
56
57
58
59
60
61
62
# This code is made by MRayan Asim
import time
print(
"Hello this number checker program is made by MRayan Asim hope you will like it 😊"
)
time.sleep(5)
def gcd(a, b):
# Compute the greatest common divisor (GCD) of two numbers
while b != 0:
a, b = b, a % b
return a
def find_coprimes(num):
coprimes = []
for i in range(2, num):
if gcd(num, i) == 1:
coprimes.append(i)
return coprimes
while True:
try:
num = int(input("Enter the number: "))
break
except ValueError:
print("Please enter a valid number.")
# Check if the number is odd or even
if num % 2 == 0:
print(num, "is an even number")
else:
print(num, "is an odd number")
# Define a flag variable
flag = False
if num < 2:
print(num, "is not a prime number")
else:
# Check for factors
factors = []
for i in range(2, num):
if num % i == 0:
# If factor is found, set flag to True
flag = True
factors.append(i)
# Check if flag is True
if flag:
print(num, "is not a prime number")
print("Factors:", factors)
coprimes = find_coprimes(num)
if coprimes:
print("Co-prime numbers:", coprimes)
else:
print("There are no co-prime numbers.")
else:
print(num, "is a prime number")