Jump to content


Photo

Chapter 5 Code Question


  • Please log in to reply
2 replies to this topic

#1 Tanner G Seymour

Tanner G Seymour

    Active Member

  • Members
  • PipPip
  • 10 posts

Posted 17 April 2015 - 08:02 PM

import sqlite3
 
def find_details(id2find):
    db = sqlite3.connect("surfersBD.sdb")
    db.row_factory = sqlite3.Row
    cursor = db.cursor()
    cursor.execute("select * from surfers")
    rows = cursor.fetchall()
    cursor.close()
    for row in rows:
        s = {}
        if row['id'] == id2find:
            s['id']       = str(row['id'])
            s['name']     = row['name']
            s['country']  = row['country']
            s['average']  = str(row['average'])
            s['board']    = row['board']
            s['age']      = str(row['age'])
            return(s)
    return({})
 
lookup_id = int(input("Enter the ID of the Surfer : "))
surfer = find_details(lookup_id)
if surfer:
    print("ID:         " + surfer['id'])
    print("Name:       " + surfer['name'])
    print("Country:    " + surfer['country'])
    print("Average:    " + surfer['average'])
    print("Board Type: " + surfer['board type'])
    print("Age:        " + surfer['age'])
 
 
im getting the error:
 
Traceback (most recent call last):
  File "C:/Python34/guessing game/surf-a-thon Surfer ID.py", line 23, in <module>
    surfer = find_details(lookup_id)
  File "C:/Python34/guessing game/surf-a-thon Surfer ID.py", line 7, in find_details
    cursor.execute("select * from surfers")
sqlite3.OperationalError: no such table: surfers
 
 
any thoughts?wacko.png

 



#2 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 19 April 2015 - 10:58 AM

Hi Tanner!

 

I think either you forgot to put the surfersBD.sdb file into the same directory as your script

 

or

 

the name of the file you downloaded is surfersDB.sdb not surfersBD.sdb

 

smile.pngcool.png



#3 Tanner G Seymour

Tanner G Seymour

    Active Member

  • Members
  • PipPip
  • 10 posts

Posted 20 April 2015 - 06:01 PM

wow, haha thanks :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users