I’m a beginner when it comes to Python and I’m trying to write code that adds typed in numbers to a list.
box = [int(x) for x in input("Type numbers here: ").split()]
box.sort(reverse=False)
print(box)
This code works fine but gets ValueError whenever there is any special character added. Meaning you need to type numbers with spaces between them and if there is a coma added it just doesn’t work. Which isn’t ideal because it’s not allowing float numbers and makes typing characters in rather clunky.
I was trying to change type to float to allow numbers such as 2,5 and to experiment with ‘re.sub()’ but it doesn’t really work for me and I am not sure how to proceed with it.
Mae Twost is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1