在我的cod中转换速度

2024-04-26 03:45:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我事先写了一段代码,但老师刚刚告诉我速度应该是每小时,而不是每分钟。我做了必要的修改,但不断收到错误。代码的上下文并不重要。你知道吗

import re

# DATA
distance = 0.06 # Distance between the Camera A and B; 0.06 = 600 metres
speed_limit = 20 # (meters per second)

number_plates = ["DV61 GGB",      #UK
                 "D31 EG 2A",     #F
                 "5314 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.17,7.22,7.12,7.23,7.41,7.18,7.25,7.11,7.38]
leave = [7.56,7.39,7.49,7.56,7.45,7.57,7.22,7.31,7.59,7.47]

mph=2.236936

# Find the non-UK plates
pattern = "(?![A-Z]{2}\d{2}\s+[A-Z]{3}$)"
foreign_numbers = list(filter(lambda x: re.match(pattern, x), number_plates))

# Calculations for speed
elapsed = [(l - e)/100 for l, e in zip(leave, enter)]
speed_mps = [distance/t for t in elapsed]

def mps_to_mph():
    speed = [s*h for s,h in zip(speed_mps,mph)]

mps_to_mph()
print(speed)

错误:

>>> 
Traceback (most recent call last):
  File "M:\ICT Coursework\Task 2.1.py", line 35, in <module>
    mps_to_mph()
  File "M:\ICT Coursework\Task 2.1.py", line 33, in mps_to_mph
    speed = [s*h for s,h in zip(speed_mps,mph)]
TypeError: zip argument #2 must support iteration

也许,speed = [s*h for s,h in zip(speed_mps,mph)]不是转换速度的正确方法吗?你知道吗


Tags: theto代码inrefor错误zip

热门问题