I opened Python and attempted to run the following script (btw, this script is what was directly given to me, I haven't edited it in any way as it's part of an assignment aside from entering the username and the password where the astericks are):
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_severityFROM accidents_2016 AS aJOIN vehicles_2016 AS v ON a.accident_index = v.Accident_IndexJOIN vehicle_type AS t ON v.Vehicle_Type = t.vcodeWHERE t.vtype LIKE %sORDER 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])/2print('Finding median for',cycle[0])cur.execute(insertSQL,(cycle[0],med_sev))
myConnection.commit()
myConnection.close()
I did the import with the pymysql and installed it via the command line. Additionally, after reading a few other responses due to other errors, I installed the pop cryptography as well. Each time I run the script, I get a new error. Now when I run it, it gives me a different error:
Traceback (most recent call last):File "H:/School/ITS 410/Mod 8/Portfolio.py", line 22, in <module>med_sev =(accidents[quotient][1] + accidents[quotient+2][1])/2
IndexError: tuple index out of range
I have only seen this one other time and it was also in Python but I don't remember what it means or how I fixed it.