+ 2

How do I fix a bug that displays "00" before my code

I just made a simple calculator, but it displays "00" before "The answer is", this also happened before I included this string https://sololearn.com/compiler-playground/cKP4O4A18BvH/?ref=app

10th Mar 2024, 6:27 AM
Alejandro Salcedo Chacón
Alejandro Salcedo Chacón - avatar
4 odpowiedzi
+ 5
Remove the int() out of the input() calls. Also, it might look a little nicer if you weren't converting string to int at the level of the display, but earlier. It makes clear that these values are integer. Also, later, it gives you the possibility to error check the input when attempting to convert non-integer values. Means, you could do as follows: a=int(input()) And then: print(a - c) A little explanation of what happens in your code: Apparently, int() called with no argument returns zero. And whatever is as parameter inside input() is taken as prompt and printed on screen prior to taking input. Hence, input(int()) prompts the return value of int() before taking input. Since you do that twice, you get "00" on the screen.
10th Mar 2024, 6:36 AM
Gordie
Gordie - avatar
+ 4
a=int(input()) b=input() c=int(input()) if b=="-": print("The answer is:", a-c)
10th Mar 2024, 8:36 AM
JaScript
JaScript - avatar
+ 2
I guess, there were some problem in comments. Or maybe that you used the int() function explicitly twice on a single variable. 🙄 No sure, but hope that the below solution may help you a bit. ☺️ https://sololearn.com/compiler-playground/cl9Y39hd17Gx/?ref=app
10th Mar 2024, 7:02 AM
I-M-J
I-M-J - avatar
+ 2
Thanks to y'all for helping me :)
10th Mar 2024, 4:26 PM
Alejandro Salcedo Chacón
Alejandro Salcedo Chacón - avatar