Share your repls and programming experiences

← Back to all posts
A calculator
OllieDuda (2)

Technically this is a fully operational calculator however it will not take negative numbers or decimals. If someone does click on this, please check out the code and tell me how you could possibly include negative, decimal and normal integers

Edit: It can now take both decimal and normal integers

Commentshotnewtop
ApoorvAgrawal (14)

Instead of using int() use float()
int is only for whole numbers, while float supports both whole numbers and decimal numbers
here's an example:
https://repl.it/@ApoorvAgrawal/RapidEnragedSpof

OllieDuda (2)

@ApoorvAgrawal Thanks, is there also i way to make it so that it will restart automatically after the calculation has been completed?

ApoorvAgrawal (14)

@OllieDuda
I have a suggestion, you could put all the math that the program has to do inside a function and put that at the top of the page, so it looks a lot less cluttered, and don't operate on the variables inside of the print statement.
So back to your question:
Do you mean like clear the screen, or run the program again.

If you want to clear the screen, you could import os, and then do os.system('clear')

If you want to run the program again, you could use a while loop. like: while 0==0:

OllieDuda (2)

@ApoorvAgrawal so ive put in the while loop however its restarting in a function. So for example, I select the addition function and I put in my numbers but when the calculation is complete it restart in the addition function instead of the end.

Put simply, I would like it so the program returns to the 'Select Functions' after the user has received their answer.

ApoorvAgrawal (14)

@OllieDuda
You would have to put the while loop higher, before the input

OllieDuda (2)

@ApoorvAgrawal oh right thanks. Still don't know how to allow the user to use negative numbers.

Edit: I've just tried to use negative numbers and it works so forget I said anything. Thanks a lot for your help, it's appreciated! :)