Why do I get this error?
and its output:
lst.append(int(input()))
ValueError: invalid literal for int() with base 10: ''
lst = []
for n in range(n):
lst.append(int(input()))
Why do I get this error?
and its output:
lst.append(int(input()))
ValueError: invalid literal for int() with base 10: ''
lst = []
for n in range(n):
lst.append(int(input()))
The error is given because you are pressing enter, sending an empty string ''
to the input()
, which cannot be interpreted as an int.
Also its probably a good idea to change first n
in for n in range(n)
with something else.
Probably because you're inputting something that's not an int.
Your int(input())
tries to convert its type to int, so if you're typing 'hello' or 5.154 it will fail.
You can just leave lst.append(input())
to get any value as string or lst.append(float(input()))
if you're inputting a float number.