0
Whats wrong with this code?
I tried to make a calculator like the one in the course but only adding works for some reason. Whats wrong? https://code.sololearn.com/cM0ZL3Urcba3/?ref=app https://code.sololearn.com/cM0ZL3Urcba3/?ref=app
4 Answers
+ 1
Replace
if userinput == "Plus" or "plus" or "+":
By
if userinput == "Plus" or userinput=="plus" or userinput=="+":
also,
to quit
import sys
sys.exit()
+ 1
Yeah got it, its working now. Thanks!
0
Pulkit Kamboj why use sys.exit() instead of break? What are the pros and cons of break/sys.exit()
0
Well, using break is fine here(as there is only one loop), but in some cases such as when you have nested loops or we have some set of statements outside the loop, then we have to look between exit and break that which one to use, for e.g. if you do not want to execute the statements after loop, then you will use exit else you will use break.
In short ,
Break only terminates you from the current loop it is present in but exit terminates you from entire program