Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
38 lines (36 loc) · 1.48 KB

File metadata and controls

38 lines (36 loc) · 1.48 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
def calc(choice, first_num, second_num):
# Python does not have switch case
# There are other ways to implement this, dictionary mapping for example, but I started off with this
if(choice=='addition' or choice=='add'):
return first_num+second_num
elif (choice=='subtraction' or choice=='subtract'):
return first_num-second_num
elif(choice=='multiplication' or choice=='multiply'):
return first_num*second_num
elif (choice=='division' or choice=='divide'):
return first_num/second_num
print("This is the Basic Calculator Program")
start=input("Do you wish to start? Type 1 for YES and 0 for NO: ")
st=int(start)
if(st!=1 and st!=0):
print("I'm going to take that as a YES")
while (st==1):
num1=input("Enter the first number: ")
first_num=int(num1)
# I could use some thing like
# Press the corresponing number to perform the operation
# 1. Addition
# 2. Subtraction
# And so on, but I wanted to attempt taking a word input
choice=input("Addition, subtraction, multiplication or division? ")
choice=choice.lower()
num2=input("Enter the second number: ")
second_num=int(num2)
answer=calc(first_num, choice, second_num)
a=int(answer)
print("The answer is "+str(a))
continue_=input("Do you want to continue? Press 1 for YES and 0 for NO: ")
st=int(continue_)
if(st!=1 and st!=0):
print("I'm going to take that as a no...")
print("Thank you for trying out the Bacic Calculator Program!")
Morty Proxy This is a proxified and sanitized view of the page, visit original site.