Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems with calculator
#2
I think the problem might be that you keep removing the results after inserting them. Take lines 67 and 68. You insert the result of the subtraction, and then immediately remove that same position.

The first part of the program seems overly complicated. It looks like you want to make sure there are no spaces except there must be spaces around the operators (so the split works to make a list of numbers and operators). Wouldn't it be simpler to just use replace for each operator (replace('+', ' + '))?

Also, I think slice assignment would work better than all that popping and inserting: s[s.index(i)-1:s.index(i)+2] = [v].
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Problems with calculator - by muachihiyo - May-02-2019, 09:00 AM
RE: Problems with calculator - by ichabod801 - May-02-2019, 10:59 AM
RE: Problems with calculator - by muachihiyo - May-02-2019, 03:45 PM
RE: Problems with calculator - by ichabod801 - May-02-2019, 06:12 PM

Forum Jump:

User Panel Messages

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