Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python, how can I use stack inside a function for a calculator program? ps: I coded all the functions, but I just need help

In python, how can I use stack inside a function for a calculator program?image text in transcribed

ps: I coded all the functions, but I just need help for the calc function(the last one).

Example of expression is: 2*(4+2*(5+3^2)+1)+4

Then, use the stack to find an innermost pair of parentheses. Calculate the inside by _calc

class stack: class node: defint (self): def Jen (self) def push,self, yal): #It adds a new node including VA, at the top pointer def pop (self): def def exRx(self, numl, gRR, num2): return numl+num2 edit, opp-"-". return numi-num2 edit, opp-'' * " : return numi*num2 if num20: print("zero division error: exeR") return "zero division error: exeopr else: return numlum2 return numl ** num'2 else: print("fatal internal error in exeopE") return "fatal internal error in eXet?; def cale(expr): # copy the body of Gale(expr) of HW2 def cale(expr) # Required: Gale must create a stack to substantially use it for parenthesis matching # Call-Gale to computer the inside parentheses class stack: class node: defint (self): def Jen (self) def push,self, yal): #It adds a new node including VA, at the top pointer def pop (self): def def exRx(self, numl, gRR, num2): return numl+num2 edit, opp-"-". return numi-num2 edit, opp-'' * " : return numi*num2 if num20: print("zero division error: exeR") return "zero division error: exeopr else: return numlum2 return numl ** num'2 else: print("fatal internal error in exeopE") return "fatal internal error in eXet?; def cale(expr): # copy the body of Gale(expr) of HW2 def cale(expr) # Required: Gale must create a stack to substantially use it for parenthesis matching # Call-Gale to computer the inside parentheses

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions