Trying to Make a Basic Calculator in Python, need help


I’m using Python for the first time to make a calculator with basic functions but I need help. I have everything,except having the calculator to continue with the answer it gets. For example it can do “3 * 4 = 12” then “12 + 2= 14” but after that I can’t get it in a while loop to continue using the last number from the calculation. I have the numbers has variables if that makes since and of course I can’t just make a new variable for every answer.
I really want to know if there’s a way I can get the code to make a " answer_=" where the _ starts at 4 and continues to add by one after ever calculation in the while loop. Help?


Here is the failing loop for more reference. As you can it continues to use the 24 and not the 30.


On line 49 you are using answer instead of answer2. Suggest re-use the variable rather than creating more.

We can help a lot more if we are given raw code, or a link the REPL page you have (be sure to save it or the link won’t work).

You are using Python 2 on a site that supports Python 3. Any reason why?



No, no reason, I thought I pressed Python 3 but I guess I didn’t, Should I copy the code and put it on Python 3?.

EDIT: Thank you, after a few minutes since reading your reply I changed it so that answer3 wasn’t a thing and it would take the answer and change it. The thing now is how do i make it so that on line49 if no is typed then the program will stop? Because when I type no it’s in the loop so it will just go back to the start of the loop.

EDIT #2: Nevermind I fixed that too, thank you for the help it works normally now. Do you know how to add color to the words and/or center the text(the title in my case)?


There is no way that I know of to apply style rules in the interactive console. It obviously supports color else everything would be white. How to manipulate those colors is beyond me. As for centering, that too is not supported.

In Python 3 the .format function does have some padding provisions along with field width.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.