I have this code that receives input of a country:
flag1 = input("Enter country 1: ")
while not worked:
worked = True
try:
code1 = pycountry.countries.get(name=flag1).alpha_2
except AttributeError:
try:
code1 = pycountry.countries.get(official_name=flag1).alpha_2
except AttributeError:
print("Invalid Input. Visit --- for list of country names.")
flag1 = input()
worked = False
I am planning to add two more ways of inputting a country (by 2/3-letter codes) so I'll have 2 more try-except statements. Is there an easier, simpler way to do this check, without having to nest 4 of these statements?