-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL1.py
More file actions
49 lines (37 loc) · 1.16 KB
/
Copy pathL1.py
File metadata and controls
49 lines (37 loc) · 1.16 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
46
47
48
49
print("---------- Simple Calculator ----------\n")
while True:
num1 = float(input("Enter First Number : "))
num2 = float(input("Enter Second Number: "))
print("\nChoose Operation")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
choice = int(input("\nEnter Choice (1-4): "))
if choice == 1:
result = num1 + num2
operation = "+"
elif choice == 2:
result = num1 - num2
operation = "-"
elif choice == 3:
result = num1 * num2
operation = "*"
elif choice == 4:
if num2 != 0:
result = num1 / num2
operation = "/"
else:
print("\nCannot divide by zero!")
continue
else:
print("\nInvalid Choice!")
continue
integer_result = int(result)
print("\n---------- Result ----------")
print(f"{num1} {operation} {num2} = {result:.2f}")
print("\nAfter Typecasting to Integer result =", integer_result)
again = input("\nDo you want another calculation? (yes/no): ")
if again.lower() != "yes":
print("\nCalculator Closed.")
break