Python的输入和数据验证程序不工作

Python的输入和数据验证程序不工作,python,Python,我正在做一个程序,它将计算飞行时间,但我似乎无法理解这一点。我基本上展示了可供选择的潜在机场。如果用户输入的内容不准确,我希望问题循环直到正确为止。否则,程序应继续进行。但是,它不起作用: airports = { "New York": {'JFK', "LGA"}, "California": {"LAX", "LGB"} } def list_airports(city): i

我正在做一个程序,它将计算飞行时间,但我似乎无法理解这一点。我基本上展示了可供选择的潜在机场。如果用户输入的内容不准确,我希望问题循环直到正确为止。否则,程序应继续进行。但是,它不起作用:

airports = {
  "New York": {'JFK', "LGA"},
  "California": {"LAX", "LGB"}
}

def list_airports(city):
  if origin == city:
    print(airports[city])
  elif destination == city:
   print(airports[city])

def data_validator(var1, var2):
  if var1 not in var2:
    print("Uh oh! That's not valid. Please be mindful that the program is case sensitive.")
    input("Try again: ")

origin = input("What state are you flying from? Type the number from the list: ")
data_validator(origin, airports)

l.append(origin)
list_airports(origin)

airport1 = input("Ok! Which ariport are you flying from the list above? Type the three letter airport code: ")
data_validator(airport1, list_airports) 

destination = input("What state are you going to?: ")
list_airports(destination)
airport2 = input("Ok! Which ariport from the list above? Type the three letter acronym for the airport: ")
错误消息如下所示:

回溯(最近一次呼叫最后一次):
文件“main.py”,第31行,在
数据校验器(机场1,列表机场)
数据校验器中第13行的文件“main.py”
如果var1不在var2中:
TypeError:类型“function”的参数不可iterable

列表\u机场是一个功能,而不是可以评估的值。您希望您的数据验证程序为:

data_validator(airport1, airports[origin])

这将根据您所在州的机场代码评估用户输入。

列表机场在这里做什么,添加您的完整代码。当用户第一次进入哪个州时,例如纽约,列表机场将列出该州机场的三个字母代码。这是不够的,列表机场是罪魁祸首。嗯,
list\u机场
是一项功能。您希望数据确认器(airport1,list\u airports)做什么?您想用list\u airports做什么?它没有定义在你的和平的代码!列表似乎是一个函数,因此错误是正常的