num = 0
for i in range(5):
ask = int(input())
if abs(ask) > 0:
num = ask
print(num)
When I run the code, it lets me input the first string. But once I enter the second string, the program crashes and says "pythonProject\main.py", line 3, in ask = int(input()) ValueError: invalid literal for int() with base 10: ''"
What's going on?
My input: I just type 1, press enter, type 2, press enter and then it crashes. I am sure it is not an error where I click enter too quickly, or I accidentally type in an empty string because I've ran the code multiple times.
What have I tried so far?
- Creating a new project and pasting the code -> didn't work
- Asking my friend to copy the code onto his PyCharm and run it -> worked fine on his computer
- 'Edit configurations', uncheck 'emulate code in output console' -> didn't work, it was already unchecked
- Checked that I was running the correct file in the project -> didn't work, I was running the right file
EDIT:
- FIXED, just needed to check 'Emulate code in output console' rather than uncheck it. Not sure why this works though, or how I can keep it checked for all future projects - rather than having to manually check it every time.