Need a different function for the python program display_ticket
def display_tickets():
t = Texttable()
tickets=cur.execute('''SELECT * FROM tickets''')
for i in tickets:
t.add_rows([['tid', 'actual_speed','posted_speed','age','violator_sex'],list(i)])
print()
print(t.draw())
print()
Need a different function for the python program add_ticket
def add_tickets():
actual_speed=int(input("enter actual speed:"))
posted_speed=int(input("enter posted speed:"))
age=int(input("enter age:"))
sex=input("Male or Female:")
cur.execute('''INSERT INTO tickets(actual_speed,posted_speed,age,violator_sex) VALUES(?,?,?,?)''',(actual_speed,posted_speed,age,sex))
con.commit()
If you'd like to see what thousands of traffic tickets look like, check out this link: https://www.twincities.com/2017/08/11/we-analyzed-224915-minnesota-speeding-tickets-see-what-we-learned/
Extracted text: We have looked at a variety of ways to store information using Python. But a company of any size does not use text files, or pickle things. They use, in almost all case, a relational database management system. We are going to use sqlite3 for this assignment, and it will do just fine for the amount of data we intend to Global NO Variables wrangle. The database for this assignment is named tickets5.db. The tickets5.db will be provided as a zipped file later on this page. The database has a little over 20 records, all of which started out as part of a database put together in Minnesota that cataloged speeding tickets issued in 2014. The original database had thousands of records. I have whittled it down for this assignment to about 22 simplified records. The table holding these records is named tickets. The first rows look like this. Table: tickets tid actual_speed posted_speed age violator_sex Filter Filter Filter Filter Filter 1 1 95 70 20 Female 95 70 25 Male 3 76 55 25 Male 4 4 77 60 27 Male 5 83 70 51 Female The tickets table has these 5 fields. Do not modify the database name, the table structure, or modify the column names; your code should work with my copy of the database. • tid is an auto-incrementing primary key • the next 3 fields: actual_speed, posted_speed and age, are all of type integer the last field, violator_sex, is of type string. Here is the link to the database. Unzip before using: tickets5.zip Your program should be able to read the table in this database and be able to perform the following functions. Menu options. Choose 1, 2, 3, or 4 1. Display all Tickets 2. Add a Ticket 3. Filter by Offender Sex 4. Save & Exit Enter your choice, 1, 2, 3, or 4: 2.
Extracted text: .Your program must have a main() function and separate functions to handle the display of all tickets, and the ability to add a new ticket record to the tickets table. For option 3 your function should allow the user to enter either 'Male' or 'Female' and then have your code filter the tickets table and show either all the Male offenders or all of the Female offenders. When data is printed it all the data should be properly aligned and look neat. Whether you are printing all the tickets or only part of them, your output should display this information: ticketID, Posted MPH, MPH Over, Age, and Violator Sex. ticketID Posted MPH MPH Over Age Violator Sex 2 70 25 25 Male 3 55 21 25 Male 4 60 17 27 Male and so on It is important to note that the original table has Posted MPH (posted_speed) and actual_speed. You must calculate and display the MPH over the posted speed limit rather than displaying the actual_speed itself mph over = actual speed posted speed. For example the ticket associated with tid = 1 was doing 95 in a 70mpg zone, so miles over is 95 - 70 = 25. There are programs similar to this assignment in week 12, More Data, and week 13, Classes 1. Study these examples carefully before starting to code. In particular there is an explicit hint near the end of the week 13 lecture notes that should be very useful.