注意:我是Python新手。
我有一项任务是设计一个程序,输出外部号牌,但只有才能超速。我可能在这个过程中犯了一些错误,但我需要帮助列表Timestaken2和字典Timestaken3。
#UK
和#F
只是我的笔记,让我能够快速查看哪个是英国车牌号,哪个是 F 的外国人。
import re
distance=750 #variable for the distance between the Camera A and B (in m)
speedlimit=70 # (mps)
NumberPlates=["DV61 GGB",#UK
"DS11 EUBG 20",#F
"5T314 10A02",#F
"24TEG 5063",#F
"TR09 TRE",#UK
"524 WAL 75",#F
"TR44 VCZ",#UK
"FR52 SWD",#UK
"100 GBS 12",#F
"HG55 BPO"#UK
]
Enter=[7.12,7.15,7.24,7.45,7.28,7.31,7.18,7.25,7.33,7.38] #A list for the times of cars passing Camera A
Leave=[7.56,7.24,7.48,7.52,7.45,7.57,7.22,7.31,7.37,7.47] #A list for the times of cars passing Camera B
Timestaken=[]
Timestaken2=[]
Timestaken3={}
for enter_data, leave_data in zip(Enter, Leave):
Timestaken.append(leave_data-enter_data)
Timestaken=["%.2f" % (leave_data-enter_data) for enter_data, leave_data in zip(Enter, Leave)]
Timestaken2=[s.strip("0") for s in Timestaken]
Timestaken2=[s.strip('.') for s in Timestaken2]
for key,value in zip(NumberPlates,Timestaken2):
Timestaken3[key]=value
print(Timestaken3)
for item in NumberPlates:
UK_Numbers=list(filter(lambda x: re.match("[A-Z]{2}\d{2}\s+[A-Z]{3}$",x),NumberPlates))
for item in UK_Numbers:
if item in UK_Numbers:
NumberPlates.remove(item)
print(NumberPlates)
for key,value in zip(NumberPlates,Timestaken2):
Timestaken3[key]=value
print(Timestaken3)
print("10 cars have passed Camera A, then Camera B\n")
for key,value in Timestaken3.items():
speed=distance/int(value)
if speed>speedlimit:
print(key,"is speeding with",speed,"mps")
我在程序中包含了print(),以查看程序最终会做什么。我第二次这样做:
for key,value in zip(NumberPlates,Timestaken2):
Timestaken3[key]=value
我预计在此代码之后只会打印剩余的NumberPlates(可能是外来的)。问题是Timestaken2还有10个值吗?
请帮助我解决您可能遇到的任何问题。
答案 0 :(得分:2)
不太确定,但也许你只想制作一本新词典:
Timestaken4={}
for key,value in zip(NumberPlates,Timestaken2):
Timestaken4[key]=value
print(Timestaken4)
答案 1 :(得分:1)
问题是您在代码的第二部分重用target="_blank"
。如果您为加速外国汽车创建新词典TimesTaken3
,您的代码似乎按预期工作:
TimestakenForeign