-2
這裏是我的代碼:數據不保存爲txt文檔,但txt文件被創建
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()
這意味着上傳到一個文本文件註冊板和速度,如果它是有效還是無效。
你有'nnstd.open(「nnstd.txt」,「a」)'而不是nnstd = open。這兩個文件都沒有寫出你需要的信息嗎? – SuperBiasedMan
是的,兩者都失敗了 –
你的輸出是什麼?它是否仍然打印「Car ###正在以#Mph的速度」?你也試着用'registration + speed'寫'string + int' – SuperBiasedMan