Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculate stack value's
#4
It takes string as input and strings are easy to modify/organise. You can do this:
eval(str(s.pop()) + symbol + str(s.pop()))
and it automatically replaces this part that you posted:
if symbol == "+":
         plus = s.pop() + s.pop()
     elif symbol == "-":
         plus = s.pop() - s.pop()
     elif symbol == "*":
         plus = s.pop() * s.pop()
     elif symbol == "/":
         plus = s.pop() / s.pop()
You can also have a list of symbols and format them all into 1 eval function.
Reply


Messages In This Thread
Calculate stack value's - by GFreenD - May-12-2019, 06:15 PM
RE: Calculate stack value's - by michalmonday - May-12-2019, 06:32 PM
RE: Calculate stack value's - by GFreenD - May-12-2019, 06:55 PM
RE: Calculate stack value's - by michalmonday - May-12-2019, 07:15 PM
RE: Calculate stack value's - by GFreenD - May-12-2019, 07:53 PM
RE: Calculate stack value's - by Yoriz - May-12-2019, 08:07 PM
RE: Calculate stack value's - by GFreenD - May-12-2019, 08:40 PM
RE: Calculate stack value's - by Yoriz - May-12-2019, 09:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020