2015-07-08 4 views
0

Я пытался создать программу для записи скорости транспортного средства и взять в номер номерной знак автомобиля. Я попытался создать файл, но у меня есть ошибка: «str не является вызываемым», я пробовал все, что знаю, но я не могу заставить его работать. если вы можете исправить это я действительно ценю это :)Как исправить эту ошибку str?

import time 
import random 
import re #inputs a module for the regular expression 
List_of_vehicles=[]#list for the number plates 
List_of_avspeed=[]#list for the average speeds 

d = float("80.00")#the speed limit 


Begin = input("Press 'Enter' to start recording the time, from sensor1-> ") 
Sensor1=time.time() 
End = input("Press 'Enter' to stop recording the time, from sensor2-> ") 
Sensor2=time.time() 
Time=(Sensor2-Sensor1) 
rounded_up=(round(Time,2)) 
average_speed = (2/(rounded_up*0.0002)) 
rounded_up2=(round(average_speed)) 
c = "mph" 
print ("Your average speed in miles per hour is " +str(rounded_up2) +str(c)) 

v_n_p = input("Enter the vehicle number plate: ") 
if re.match("[A-Z]{2}[0-9]{2}[A-Z]{3}", v_n_p): 
    print("Your vehicle number plate is valid") 
    List_of_vehicles.append(v_n_p) 
else: 
    print("Your vehicle number plate is invalid") 
    exit() 

if (rounded_up2) <= float(d):#asks the program if the average speed is above or below the speed limit 
       print("You have not exceeded the speed limit") 
else: 
    print("You have exceeded the speed limit") 
    print("You will be charged with a £100 fine") 
    List_of_avspeed.append (rounded_up2)#this also appends to the list 


print(List_of_vehicles)#this outputs the list for vehicle number plates 
print(List_of_avspeed)#this outputs the list for average speeds 

#below, is where a file is created for the vehicle number plates entered 
Speed_limit_file=open(str(List_of_vehicles)+".txt",'w')#creation of file 
Speed_limit_file.write("Vehicle number plate is: "+str(List_of_vehicles)+"\n")#adding the number plates 
Speed_limit_file.write("Vehicle average speed is: "+str(List_of_avspeed)+"\n")#adding the average speeds 
Speed_limit_file.write("The vehicles listed above will receive £100 fine"+"\n") 
Speed_limit_file.close()#the file must be closed at the end of the program 

## main problem below, on the road list and postcode list 
if re.match("[A-Z]{2}[0-9]{2}[A-Z]{3}", v_n_p): 

    if rounded_up2 > float(d): 

     data_file= open(str(List_of_vehicles)+".txt","w") 
     data_file.write("Vehicle number plate: "+str(List_of_vehicles) +"\n") 
     data_file.write("Vehicle average speed: "+str(List_of_avspeed) +"\n") 

     owners=["Joe","Ken","Jake","Jack"] 
     names=random.choice(owners) 
     data_file.write=("The owner's name is:"+str(names) +"\n") 

     road=["54 Highgate Drive","78 Knighton Road", "67 Beligner Road"] 
     roads=random.choice(road) 
     data_file.write("The address:"+str(roads) +"\n") 

     pstcode=["LE2 6HW","UI3 7GH","OI4 8HG"] 
     pstcodes=random.choice(pstcode) 
     data_file.write("The Postcode is: "+str(pstcodes) +"\n") 

     data_file.close() 
    else: 
     (" ") 
else: 
    (" ") 
+0

Это Python? –

+0

yes it is python – thomas

+0

Ваш след должен иметь связанную с ним линию. Какая линия? – NightShadeQueen

ответ

1

Я считаю, что ваша проблема с помощью следующей строки кода

data_file.write=("The owner's name is:"+str(names) +"\n") 

Вы должны удалить «=»

data_file.write("The owner's name is:"+str(names) +"\n") 

Надеюсь, что это поможет.

+0

Большое спасибо - OMG им такой noob в любом случае thnx jharrison12 – thomas

Смежные вопросы