I'm trying to validate an input by using a list that holds the strings that are valid inputs but I can't seem to get it to work correctly, any help?
choice = ["A","a","B","b"]
def main():
test = input()
if validate(test):
print("Entered a")
else:
print("did not enter a")
def validate(val):
try:
val = choice.index[1]
except:
return False
else:
return True
main()
choice.index(val)(with parens, not brackets, and looking forval, not assigning to it). But that idiotic bareexcept:(NEVER USE BARE EXCEPT!) is masking the problem. If the except were targeted to theValueErroronly, it wouldn't mask theTypeErrorusing brackets raises. Of course, it's still a pointless way to test (return val in choicebeing correct and simpler), but that's why the original code breaks.