the code is identifying the numbers I enter as string
The function input
gives a string. You have to do the interpretation. In in this case, interpret it as an int.
imp = int(input('input a no'))
You could check for problems, in case they input something that cannot be interpreted as an int
.
try:
imp = int(input('input a no'))
except ValueError:
... # Respond to the error. For example, tell the user that they made a mistake.
thanks. it worked
when i open the code using python, when i press âenterâ after entering the no., the software just stops. any idea why that is happening?
Did you make sure the window has focus while typing? It doesnât look like the program is receiving your input at all, so itâs still waiting for you to âenter the numberâ.
Focus while typing? I donât understand.
If itâs about the first one, it was solved, thanks to @franklinvp. If itâs about second, when I enter the number and click enter, python software is just closing. Like how it does when you click the X
Oh, sorry. When you said âthe software just stopsâ I thought you meant that the window stays open and you donât see anything change inside it, like in the screenshot. That would happen if you were typing in a different program instead of that one.
The window closes because thereâs nothing more for your program to do, so Windows doesnât have a reason to keep the window open any more.
I was opening this code
try:
inp = int(input(âenter a noâ))
except:
print(âplease enter a no.â)
quit()
inp = inp + 2.5
print(âyour no isâ, inp)
using python. .
The code runs on terminal just fine. But when opened using python, the window closes as soon as I enter the number and click enter. It is not giving any output while there should be.
Exactly as I said. The output is there, you just donât get to see it because the window closed.
How do I prevent it from closing?
By checking the links I posted already and following the advice given there.