-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise10.py
More file actions
45 lines (40 loc) · 1.21 KB
/
exercise10.py
File metadata and controls
45 lines (40 loc) · 1.21 KB
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
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def is_power(a, b):
if a == 1:
return True
if a % b != 0:
return False
if a == b:
return True
return is_power(a // b, b)
def compare(x, y):
if x > y:
return f"{x} is greater than {y}"
elif x == y:
return f"{x} is equal to {y}"
else:
return f"{x} is less than {y}"
def number_tool():
# Get user input for two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# Ask user to choose an operation
operation = input("Choose operation (gcd/power/compare): ")
# Handle the chosen operation
if operation == 'gcd':
result = gcd(num1, num2)
print(f"GCD of {num1} and {num2} is {result}")
elif operation == 'power':
if is_power(num1, num2):
print(f"Yes, {num1} is a power of {num2}")
else:
print(f"No, {num1} is not a power of {num2}")
elif operation == 'compare':
print(compare(num1, num2))
else:
print("Invalid operation. Please choose gcd, power, or compare.")
# Call the function
number_tool()