-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_calculator_app.py
More file actions
37 lines (29 loc) · 871 Bytes
/
basic_calculator_app.py
File metadata and controls
37 lines (29 loc) · 871 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
36
37
print ('\n A Simple Calculator in Python \n')
def add(x,y):
return x+y
def sub(x,y):
return x-y
def mul(x,y):
return x*y
def divide(x,y):
return x/y
print ('Select operation: \n')
print (' 1.for Addition')
print (' 2.for Subtract')
print (' 3.for Multiply')
print (' 4.for Divide\n')
choice = input('Enter your choice(1,2,3,4): ')
if choice in ('1','2','3','4'):
first_num = int(input('\nEnter your first number: '))
second_num = int(input('Enter your second number: '))
if (choice == '1'):
result = add(first_num,second_num)
if (choice == '2'):
result = sub(first_num,second_num)
if (choice == '3'):
result = mul(first_num,second_num)
if (choice == '4'):
result = divide(first_num,second_num)
print("\nTotal:",result)
else:
print('Invalid')