Whats wrong with this code? | Sololearn: Learn to code for FREE!
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

27th Dec 2018, 1:28 PM
Zinnur Hossain
Zinnur Hossain - avatar
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()
27th Dec 2018, 1:42 PM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 1
Yeah got it, its working now. Thanks!
27th Dec 2018, 1:59 PM
Zinnur Hossain
Zinnur Hossain - avatar
0
Pulkit Kamboj why use sys.exit() instead of break? What are the pros and cons of break/sys.exit()
27th Dec 2018, 7:33 PM
Zinnur Hossain
Zinnur Hossain - avatar
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
28th Dec 2018, 3:00 AM
Pulkit Kamboj
Pulkit Kamboj - avatar