-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.py
More file actions
40 lines (37 loc) · 1.22 KB
/
Copy pathCalculator.py
File metadata and controls
40 lines (37 loc) · 1.22 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
#This is a simple calculator using the console
print ("Calculator program. You got following options: 1 for addition, 2 for subtraction, 3 for multiplication and 4 for division")
try:
number=int(input("Make your choice"))
while (number>4 or number<1):
number=int(input("Please select 1 for addition, 2 for subtraction, 3 for multiplication or 4 for division"))
except: print("You use the wrong input format")
#Catch when letter is inserted
try:
if (number==1):
#Addition
x=float(input("Select the first number:"))
y=float(input("Select the second number:"))
z=x+y
print (z)
elif (number==2):
#Subtraction
x=float(input("Select the first number:"))
y=float(input("Select the second number:"))
z=x-y
print (z)
elif (number==3):
#Multiplication
x=float(input("Select the first number:"))
y=float(input("Select the second number:"))
z=x*y
print (z)
elif (number==4):
#Division
x=float(input("Select the first number:"))
y=float(input("Select the second number:"))
z=x/y
print (z)
except:
ZeroDivisionError: print("You cannot devide through zero")
ValueError: print("Please use numbers")
Exception: print("Please use the proper input methods")