Skip to content

Commit

Permalink
Merge pull request #12 from PaprikaX33/statement-based
Browse files Browse the repository at this point in the history
Statement based
  • Loading branch information
PaprikaX33 authored Oct 12, 2019
2 parents bf628bf + a379d24 commit 8f98031
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions calc_main.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
#!/usr/bin/env python2
import math
import parser as pr

def add(a, b):
return a + b
def red(a, b):
return a - b
def mul(a, b):
return a * b
def div(a, b):
return a / b
def power(a, b):
return a ** b

def statement_wrapper():
doper = {
'+' : add
,'-' : red
,'*' : mul
,'/' : div
,'^' : power
}
states=raw_input(">>")
result=pr.apply(states, darg=doper)
if(result == None):
print("<< Undefined")
else:
full = "<< ", str(result)
print(full)
return

while True:
print("MENU")
print("1 for addition :")
Expand All @@ -8,41 +39,41 @@
print("5 for Division:")
print("6 for floor division:")
print("7 for factorial:")
print("8 for Statement based:")
choice=int(input("enter any choice:"))
def additon():
a=int(input("enter 1st no to perform addition:")) #a-first input
b=int(input("enter 2nd no to perform addition:")) #b-second input
c=a+b
c=add(a, b)
print("sum is:",c)
return
def subtract():
a = int(input("enter 1st no to perform subtraction:"))
b = int(input("enter 2nd no to perform subtraction:"))
c = a - b
c = red(a, b)
print("subtraction is:", c)
return
def multiplication():
a = int(input("enter 1st no to perform multipication:"))
b = int(input("enter 2nd no to perform multiplication:"))
c = a*b
c = mul(a, b)
print("multiplication is:", c)
return
def power():
a = int(input("enter base :"))
b = int(input("enter power :"))
c = a**b
c = pow(a, b)
print("division is:", c)
return

def divide():
a = int(input("enter 1st no to perform division:"))
b = int(input("enter 2nd no to perform division:"))
c = a/b
c = div(a, b)
print("division is:", c)
return
def floor_division():


#def floor_division():

def factorial():
num = int(input("enter a number: "))
if num < 0:
Expand All @@ -69,6 +100,9 @@ def factorial():
floor_division()
elif choice==7:
factorial()
elif choice==8:
statement_wrapper()
else:
print("wrong input")
exit(0)

0 comments on commit 8f98031

Please sign in to comment.