-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmycalc.py
More file actions
35 lines (26 loc) · 777 Bytes
/
Copy pathmycalc.py
File metadata and controls
35 lines (26 loc) · 777 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
34
35
# code for a simple python calculator
#prompt the user to input the first number.
num1=int(input("Enter first number: "))
while(num1==0):
print("Error")
num1=int(input("Enter first number: "))
#accepts the operator.
print("1-add, 2-subtract, 3-multiply, 4-divide")
operator=int(input("Enter operator: "))
while(operator<1 or operator>4):
print("Error")
operator=int(input("Enter operator: "))
#prompt the user to input the second number
num2=int(input("Enter a second number: "))
while(num2==0):
print("Error")
num2=int(input("Enter a second number: "))
if(operator==1):
result=num1+num2
elif(operator==2):
result=num1-num2
elif(operator==3):
result=num1*num2
else:
result=num1/num2
print(result)