forked from codemistic/General-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonCalculator.py
64 lines (49 loc) · 1.36 KB
/
PythonCalculator.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
63
64
# Python Calculator
# Created by Amey Karan
import math
print("Welcome to Python Calculator!")
print("What do you want to do today?")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Highest Common Factor (HCF)")
print("6. Least Common Multiple (LCM)")
while True:
choice = input("Enter your choice: ")
if choice in ["1", "2", "3", "4", "5", "6"]:
break
else:
print("Please select a valid choice")
print()
while True:
num1 = input("Enter the first number: ")
try:
num1 = int(num1)
break
except:
print("Enter a valid number!")
while True:
num2 = input("Enter the second number: ")
try:
num2 = int(num2)
break
except:
print("Enter a valid number!")
print()
choice = int(choice)
if choice == 1:
print(f"{num1} + {num2} = {num1 + num2}")
elif choice == 2:
print(f"{num1} - {num2} = {num1 + num2}")
elif choice == 3:
print(f"{num1} * {num2} = {num1 + num2}")
elif choice == 4:
print(f"{num1} ÷ {num2} = {num1 + num2}")
print(f"Quotient: {num1 // num2}")
print(f"Remainder: {num1 % num2}")
elif choice == 5:
print(f"HCF({num1}, {num2}) = {math.gcd(num1, num2)}")
elif choice == 6:
print(f"LCM({num1}, {num2}) = {math.lcm(num1, num2)}")
print("Thank you for choosing me. Hope to see you soon!")