a = [] for i in range (5): a.append(input ("Enter only one character: ")) a.sort() print(a) a.reverse() print(a)
This is my code and I don’t know how to detect a single character. If a user input two character they will get an error but if the user input single character the input item will be in the list.
Advertisement
Answer
a = [] for i in range (5): c = input ("Enter only one character: ") if len(c) == 1: a.append(c) else: raise ValueError("Input is not a single character") a.sort() print(a) a.reverse() print(a)