-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.py
48 lines (41 loc) · 1.64 KB
/
Calculator.py
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
user_name = input(
"Hey there ! type in your name as shown eg- 'Himanshu Lahoti'")
#space_index = user_name.find(' ')
# user_firstname = (user_name[:space_index]) i used this self made code first
# user_lastname = (user_name[space_index + 1:]) then realised when can do in 1 line why go for 3.
#words = user_name.split(" ")
user_firstname, user_lastname = user_name.split(" ")
print(f'Welcome Mr.{user_lastname}😇!')
while True:
user_input = input('''
Type 'Add' to perform Addition.
Type 'Subtract' to perform Subtraction.
Type 'Multiply' to perform Multiplication.
Type 'Div' to perform Division.
Type 'Quit' to Quit.
Note: Words are not case sensative. Type Unwisely
''').lower()
if user_input == "add":
x, y = input(
"Enter two numbers to add seperated by a space. eg '5 10': ").split()
ans = int(x) + int(y)
print(f'The sum is: {ans}')
elif user_input == "subtract":
x, y = input(
"Enter two numbers to subtract seperated by a space. eg '5 10': ").split()
ans = int(x) - int(y)
print(f'The ans is: {ans}')
elif user_input == "multiply":
x, y = input(
"Enter two numbers to multiply seperated by a space. eg '5 10': ").split()
ans = int(x) * int(y)
print(f'The ans is: {ans}')
elif user_input == "div":
x, y = input(
"Enter two numbers to divide seperated by a space. eg '5 10': ").split()
ans = int(x) / int(y)
print(f'The ans is: {ans}')
elif user_input == "quit":
break
else:
print("Wrong input")