Skip to content

Commit aed7eda

Browse files
Merge pull request raviprakashdev#13 from aaishikasb/aaishikasb
Added Calculator, Calender and ASCII Value
2 parents 6de43e8 + d0bd249 commit aed7eda

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

ASCIIValue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
c = 'p'
2+
print("The ASCII value is ", ord(c))

Calculator.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def calc(choice, first_num, second_num):
2+
# Python does not have switch case
3+
# There are other ways to implement this, dictionary mapping for example, but I started off with this
4+
if(choice=='addition' or choice=='add'):
5+
return first_num+second_num
6+
elif (choice=='subtraction' or choice=='subtract'):
7+
return first_num-second_num
8+
elif(choice=='multiplication' or choice=='multiply'):
9+
return first_num*second_num
10+
elif (choice=='division' or choice=='divide'):
11+
return first_num/second_num
12+
13+
print("This is the Basic Calculator Program")
14+
start=input("Do you wish to start? Type 1 for YES and 0 for NO: ")
15+
st=int(start)
16+
if(st!=1 and st!=0):
17+
print("I'm going to take that as a YES")
18+
while (st==1):
19+
num1=input("Enter the first number: ")
20+
first_num=int(num1)
21+
# I could use some thing like
22+
# Press the corresponing number to perform the operation
23+
# 1. Addition
24+
# 2. Subtraction
25+
# And so on, but I wanted to attempt taking a word input
26+
choice=input("Addition, subtraction, multiplication or division? ")
27+
choice=choice.lower()
28+
num2=input("Enter the second number: ")
29+
second_num=int(num2)
30+
answer=calc(first_num, choice, second_num)
31+
a=int(answer)
32+
print("The answer is "+str(a))
33+
continue_=input("Do you want to continue? Press 1 for YES and 0 for NO: ")
34+
st=int(continue_)
35+
if(st!=1 and st!=0):
36+
print("I'm going to take that as a no...")
37+
38+
print("Thank you for trying out the Bacic Calculator Program!")

Calender.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import calendar
2+
yy = int(input("Enter year: "))
3+
mm = int(input("Enter month: "))
4+
5+
print(calendar.month(yy, mm))

0 commit comments

Comments
 (0)