Question
When I run this on Python it does not give all the input, what am I doing wrong? See attached photo for results from script..
When I run this on Python it does not give all the input, what am I doing wrong?
See attached photo for results from script..
import pymysql myConnection = pymysql.connect(host='localhost', user='****', passwd='****', db='accidents') cur = myConnection.cursor() cur.execute('SELECT vtype FROM vehicle_type WHERE vtype LIKE "%otorcycle%";') cycleList = cur.fetchall() selectSQL = (''' SELECT t.vtype, a.accident_severity FROM accidents_2016 AS a JOIN vehicles_2016 AS v ON a.accident_index = v.Accident_Index JOIN vehicle_type AS t ON v.Vehicle_Type = t.vcode WHERE t.vtype LIKE %s ORDER BY a.accident_severity;''') insertSQL = ('''INSERT INTO accident_medians VALUES (%s, %s);''') for cycle in cycleList: cur.execute(selectSQL,cycle[0]) accidents = cur.fetchall() quotient, remainder = divmod(len(accidents),2) if remainder: med_sev = accidents[quotient][1] else: med_sev = (accidents[quotient][1] + accidents[quotient+2][1])/2 print('Finding median for',cycle[0]) cur.execute(insertSQL,(cycle[0],med_sev)) myConnection.commit() myConnection.close()
Python 3.4.4 Shell File Edit Shell Debug Options Window Help Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AM Lon D64)] on win32 n Type "copyright", "credits" or "license()" for more information. SAI: C:/yi.a/yikxl.py oot = Finding median for Motorcycle 50cc and under Finding median for Motorcycle 125cc and under Finding median for Motorcycle over 125cc and up to 500cc Finding median for Motorcycle over 500cc Finding median for Electric motorcycle Finding median for Motorcycle -unknown co dex %s is) en Python 3.4.4 Shell File Edit Shell Debug Options Window Help Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AM Lon D64)] on win32 n Type "copyright", "credits" or "license()" for more information. SAI: C:/yi.a/yikxl.py oot = Finding median for Motorcycle 50cc and under Finding median for Motorcycle 125cc and under Finding median for Motorcycle over 125cc and up to 500cc Finding median for Motorcycle over 500cc Finding median for Electric motorcycle Finding median for Motorcycle -unknown co dex %s is) enStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started