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
Solution 1:
if (speed>60)
#Do what you want to
Solution 2:
In this part you store speed in your variable and then in second line you overwrite it with string.
speed = (5/timetaken)
speed = ("Vehicle speed in miles per hour:")
print(speed)
As Mohit Bhasi mentioned checking the speed is not that difficult, just make sure you know what units you are working with, either meters per second or kilometers per second.
Reading/writing file is fairly simple in Python and documentation offers few examples how to do it. Or check out some other sources as well.
Regarding your task, I would do something like this:
- Open file
- Read each line with data
- Get the plates string, and speed value which you should parse to number
- Check for speed limit
- Print out
- Close file
PS: No one is going to write it for you. That would take all fun out of it. :-)
Post a Comment for "Python File Handling: Seaching For Specific Numbers"