-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek1_Pythonassignment.py
More file actions
33 lines (25 loc) · 893 Bytes
/
week1_Pythonassignment.py
File metadata and controls
33 lines (25 loc) · 893 Bytes
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
#--- Basic Calculator Program ---
# Ask the user to input the first number
num1 = float(input("Enter the first number: "))
# Ask the user to input the second number
num2 = float(input("Enter the second number: "))
# Ask the user to choose an operation
operation = input("Enter the operation (+, -, *, /): ")
# Perform the selected operation and print the result
if operation == "+":
result = num1 + num2
print(f"{num1} + {num2} = {result}")
elif operation == "-":
result = num1 - num2
print(f"{num1} - {num2} = {result}")
elif operation == "*":
result = num1 * num2
print(f"{num1} * {num2} = {result}")
elif operation == "/":
if num2 != 0:
result = num1 / num2
print(f"{num1} / {num2} = {result}")
else:
print("Error: Division by zero is not allowed.")
else:
print("Error: Invalid operation.")