I don't understand why I'm getting a Value Error. I specifically exclude the "*" character.....yet it still gets included and causes an error. I understand I have to figure out how to reverse the output too but I'll worry about that later.
Write a program that reads a list of integers, one per line, until an "*" is read, then outputs those integers in reverse. For simplicity in coding output, follow each integer, including the last one, by a comma.
Note: Use a while loop to output the integers. DO NOT use reverse() or reversed().
Ex: If the input is:
2
4
6
8
10
*
the output is:
10,8,6,4,2,
my code:
''' Type your code here. '''
while True:
try:
if input().strip() != "*":
num = input().strip()
lst = []
lst.append(num)
print("{},".format(int(num),end=""))
else:
break
except EOFError:
break
Enter program input (optional)
2
4
6
8
10
*
Program errors displayed here
Traceback (most recent call last):
File "main.py", line 8, in <module>
print("{},".format(int(num),end=""))
ValueError: invalid literal for int() with base 10: '*'
Program output displayed here
4,
8,