r/learnpython • • Jul 09 '20

I made a calculator in Python!

Hello everyone!

I just wanted to share this project i made, its not my first programming project or python project whatsoever, but it is indeed the first one i didnt depended much on google or a video tutorial so that for me its a great advance.

The project is also my first on a github repository!

https://github.com/mexicanlefty/Python-Calculator

Please take a look and test it, in case you can provide any feedback it would be even better, it doesnt matter if you guys want to be very critical, i dont mind i want to keep practicing and i already have my next project in mind.

392 Upvotes

49 comments sorted by

View all comments

10

u/james_fryer Jul 09 '20

Let's say I want to add 7 + 2.

On my pocket calculator I do this:

  • a. Press 7 (7 is displayed)

  • b. Press + (7 is still displayed, also a small + icon)

  • c. Press 2 (7 disappears, 2 is now displayed, along with the + icon)

  • d. Press = (9 is displayed)

Now I have a choice, either I can use the result (9) of the previous sum by pressing an operator, in which case it will behave as (b) above. Or, I can start a new sum by entering a number, in which case the current display is replaced with the new number as at (a) above.

On your calculator, at (b) the display is cleared, which is strange. And after (d) if I enter a new number, it is appended to the current display.

So I'd say you need to study the behaviour of a pocket calculator and make sure your program emulates it accurately.

Note that at (b) the operator is displayed, this is a feature of my calculator, but I like it.

Most calculators also support a "Constant" function. E.g. if you press 2, then '+' twice, then a number, each press of = will add 2 to the result. This is indicated by a "K" icon. Once you have the normal behaviour correct it would be interesting to add this feature.