Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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..image text in transcribed

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) en

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Why does 6( in Six Sigma really mean 4.5(?

Answered: 1 week ago

Question

=+8. Why is productivity important?

Answered: 1 week ago

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago

Question

=+6. What does the invisible hand of the marketplace do?

Answered: 1 week ago