python让用户输入数组_在Python中基于用户输入显示数组值

我有一个文本文件为数组提供数据。我用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的信息。在

任何帮助都将不胜感激。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值