我有一个文本文件为数组提供数据。我用csv导入了它们。我有多个数组,存储诸如人名、地址、电子邮件等数据。我正试图根据用户输入打印出单个数组的值。在elif option==3:
print("Which report would you like to run?")
time.sleep(1)
reportmenu()
while True:
choice=int(input(" "))
if choice ==1:
city_input=raw_input("Please enter a city which you would like to display all students from")
for row in City:
if city_input in City:
cityindex=City.index(city_input)
print("{} {} {} {} {} {} {}".format(ID[cityindex],Surname[cityindex],FirstName[cityindex],City[cityindex],Phone_Number[cityindex],Gender[cityindex],Email[cityindex]))
因此,如果用户输入城市的名称,并且它出现在城市数组中,程序可以打印出存储在其他数组中的与用户相关的其他信息。我尝试过根据用户输入建立索引,但这不起作用,我得到以下输出:
^{pr2}$
在我的文本文件(转换为csv)中,我有以下数据(到目前为止):001,Surname1,Shaun,18/09/86,Sheffield,012345,Male,shaun@shaun.com
002,Surname2,Ifty,01/01/01,Rotherham,0123456,Male,Ifty@ifty.com
003,Surname3,Dawn,01/01/01,Doncaster,0123456,Female,Dawn@Dawn.com
004,Surname4,Bryan,01/01/01,Sheffield,012345,Male,Bryan@deaf.com
所以如果用户输入'Sheffield',它应该显示Shaun和Bryan的信息。在
任何帮助都将不胜感激。在