I am trying to create a case-insensitive user input choice. But what I think should be correct isn't working. This is the relevant snippet of code:
while True:
search = raw_input("Choose search A or B: ")
search = search.lower()
if search != {'A','B'}:
print "That was not a valid choice."
else:
if search == 'A':
searchAfunction()
if search == 'B':
searchBfunction()
else:
print "Search again."
I want the user to be able to input 'a' or 'A'. At the moment this is the only working solution I have is this. It doesn't seem very Pythonic?:
while True:
search = raw_input("Choose search A or B: ")
if search != {'A','a','B','b'}:
print "That was not a valid choice."
else:
if search in {'A','a'}:
searchAfunction()
if search in {'B','b'}:
searchBfunction()
else:
print "Search again."
When I include the search = search.lower() I just get stuck in a loop of "Search again". (In the full program this allows the user to choose to search again by A or B after completing a search). Any ideas?