这是我的密码:
import re
import time
uk=open("uknp.txt", "w")
nnstd=open("nnstdnp.txt", "w")
uk.close()
nnstd.close()
while 1:
distance=1
print("------------------------------------")
registration = input("Please Enter the Registration Plate: ").lower()
time = float(input("How long did it take you to reach 1 mile in seconds: "))
speed=((distance/time)*60)*60
print("Car",registration,"was going at" ,"%.2f" %speed,"Mph")
if speed>60:
if re.match("[a-z]{2}[0-9]{2}[a-z]{3}!", registration):
uk=open("uknp.txt", "a")
uk.write(registration + speed)
uk.close()
else:
nnstd.open("nnstd.txt", "a")
nnstd.write(registration+speed)
nnstd.close()
它的意思是上传到一个文本文件的车牌和速度,如果它是有效的或无效的
您的代码中有几个错误
nnstdnp.txt
文件,然后编写一个nnstd.txt
nnstd.open("nnstd.txt", "a")
当它应该是nnstd=open("nnstd.txt", "a")
xx.write(registration + speed)
中引发TypeError: Can't convert 'float' object to str implicitly
,而它应该是xx.write(registration + ("%02f" % speed))
你没有结束条件离开你的
while 1:
循环;可能是:一般的建议是,当出现问题时,应该尝试添加
print
调用,以查看到底发生了什么以及遵循了if
的哪些分支相关问题 更多 >
编程相关推荐