【发布时间】:2021-11-17 14:18:37
【问题描述】:
我正在尝试创建一些代码,用户将在其中键入类别值,如果一行中的特定列 == 该类别,那么它将以下面的格式显示该行。出于某种原因,我的代码只找到数组中与该列相等的第一行,但即使该列等于用户输入,也会跳过其余行。
例如,如果有人输入 Development 作为类别.. 它应该在第 7 列中设置 Development 的所有行(即第 1 行和第 5 行) 非常感谢任何帮助找出问题的帮助
contact_list = [[1,'Athena','Brizell','Vitz','9 Northview Hill',5888510700,344-241-3276,'Development','4/27/2021','10/29/2021','Athena Brizell'],
[2,'Isadore','Ander','Wordtune','72660 Orin Road',4848283832,877-155-7495,'Office_fitting','4/25/2021','9/26/2021','Isadore Ander'],
[3,'Hannis','Matches','Realpoint','847 Schurz Park',9052187780,368-121-1215,'Office_fitting','1/8/2021','9/4/2021','Hannis Matches'],
[4,'Cindee','Breadon','Gigashots','3 Bultman Way',4543988898,155-423-5293,'Support','4/25/2021','6/29/2021','Cindee Breadon'],
[5,'Baron','Arnao','Thoughtstorm','856 Blackbird Road',9831465576,207-486-1010,'Development','4/30/2021','10/28/2021','Baron Arnao'],
[6,'Laureen','Kearney','Dablist','70525 Texas Terrace',6091413184,602-843-9500,'Office_fitting','3/3/2021','9/3/2021','Laureen Kearney']]
category = input('Please enter the category you wish to display contacts for (Development/Office_fitting/Support: ')
for row in contact_list:
if row[7] == category:
firstname = f'Firstname: {row[1]}\n'
lastname = f'Lastname: {row[2]}\n'
company = f'Company: {row[3]}\n'
address = f'Address: {row[4]}\n'
landline = f'Phone: {row[5]}\n'
mobile = f'Mobile: {row[6]}\n'
category = f'Category: {row[7]}\n'
date_created = f'Date Created: {row[8]}\n'
date_modified = f'Date Updated: {row[9]}\n'
print(firstname, lastname, company, address, landline, mobile, category, date_created, date_modified)
【问题讨论】:
标签: python python-3.x list