I am reading a user input which must be a character and a integer within a limit.
Let's say I have a list 's' of size 3, then the user input must be "s%d" where %d must be 1, 2, or 3. The size can vary, so using:
choice == "s1" or choice == "s2" or ...
would not work.
Here is what I have:
num = [range(1, len(input) + 1)]
if choice == "s%d" %d in num:
Just check if the number from the user input is in your list len range, u can do:
num = [range(1, len(input) + 1)] choice = input("Enter 's' followed by a number: ") if int(choice[1:]) > len(l): # It will work if indeed the single <do something> # letter is followed by an int.