Im trying to make a program that you can add string to a list. For example 'Apple'. It sorts them into alphabetical order and ends the loop on a empty input
I've tried expect valueErrors and SyntaxError none of them work for string. I've also tried if(str(input) == Null) but that diden't work as id expect or want
try:
ostos = []
while True:
ostos.append(str(input("Lisää listalle:")))
print("Listalla on", len(ostos), "riviä:")
ostos.sort()
print(ostos)
except:
print(ostos)
It would as for a input into the list. It would add Apple, Banana and Orange to the list. Put them in alphabetical order every input. And it would end on a empty input
Lisää listalle: Apple Listalla 1 riviä: Apple Lisää listalle: Orange Listalla 2 riviä: Apple, Orange Lisää listalle: Banana Listalla 3 riviä: Apple, Banana, Orange Lisää listalle: Listalla 3 riviä: 'Empty' Apple, Banana, Orange