+ 1
Calculator problems
Iâve been working on this calculator... Does anyone know whatâs wrong? https://code.sololearn.com/caD5fjyInzI3/?ref=app
2 RĂ©ponses
0
All right...
So first thing: before every elif and before the else at the bottom, indent result = ... and the print statement after that. That way you make sure that those statements are executed in the previous if or elif. Otherwise they will be executed outside of it, marking that we have gotten out of the condition. And if we are out of it a new elif or else is not valid.
Now: to test your code, you can input one of your operation, go to the next line input a float, and next line another float...
eg:
add
15
4
The reason for this is that here on Code Playground the system does not prompt the user for inputs several times. It does only once at the beginning. So an input like that will give you an output once.
Now, because you are running the loop and prompting the user for an input until you get an invalid input, you might get an error at some point cause the system won't actually let you input values while the program is running... On another platform this will work fine but not here.
0
Alternatively you can input right at the beginning everything you want to do. Say:
add
15
4
subtract
23
5
quit