Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

Python File handling: Seaching for specific numbers

I'm creating a document in which I need to record license plates of vehicles (it's a practice exercise, nothing illegal) and calculate the speed they travel at and display all the vehicles that are travelling over 60 miles per hour. I'm pretty new to file handling and have no idea how to get Python to search for specific numbers. Help!

Code so far:

plate = "blank"
sensor1 = "blank"
sensor2 = "blank"
timetaken = "blank"
speed = "blank"

plate = input("Please input the license plate of the vehicle.")

sensor1 = float(input("Input the time the vehicle passed sensor 1."))
sensor2 = float(input("Input the time the vehicle passed sensor 2."))

timetaken = (sensor2 - sensor1)

print("The time taken for the vehicle to travel between the two sensors in  seconds:")
print(timetaken)

speed = (5/timetaken)
print("Vehicle speed in miles per hour:")
print(speed)

Edit: I appreciate the help but I'm not sure how I can search the .txt document that will be created later on to search for a specific license plate.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
if (speed>60)
    #Do what you want to 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...