Why am I getting an error with map() function in the following code? Why can't map convert negative numbers in the list x
. The output should be like "1 --> 2 --> 3". The list should end whenever I enter -999
. I am getting an error such as:
Traceback (most recent call last):
File "c2.py", line 3, in <module>
x=map(int,x)
ValueError: invalid literal for int() with base 10: '-'
Code:
while(1):
x=list(raw_input("Input a number\n(type -999 to end);"))
x=map(int,x)
if x<0:
break
pass
print x
del x[len(x)]
for i in range(0,(len(x))):
print "%d-->" %(x[i]),