如何在包含字符串和数字的行文件中找到最大数字的行
def topSpeed(cars):
y = raw_input("car type:")
with open("cars","r") as f:
for l in f.readlines():
list = []
p = l.strip().split("|")
type = p[1]
max_speed = p[7]
if y == type:
list.append(l)
a = 0
for i in list:
p = i.strip().split("|")
max_speed = p[7]
if max_speed > a:
a = max_speed
print(i)
pass
else:
print("...")
else:
print("no cars of that type")
我试过了,但它打印了所有输入类型的汽车
和汽车清单是:
a1|bmw|a|3.5|2.6|1.6|2018|150|3|5|x
a2|audi|a|2.50|1.60|4.50|2017|220|3|2|y
a3|audi|b|2.30|1.80|5.00|2011|180|4|4|x
a4|bmw|b|duz|vis|sir|god|230|3|5|y
LEATH
相关分类