Hi I am new to Python. I am stuck on this question..... I know it is only simple but it just will not work for me and I have spent hours looking at the screen.. :(
below is some code. The first fuction is to simply return the average rating of the video and a count.... I thought I did this right as when I create a separate shell that links to the database it provides the average and the count. (number of ratings added to the database) But when I run the the test script it comes up with an error message saying
line 145, in test_average_ra ting
(avg, count) = util.average_ra ting(vid)
TypeError: 'NoneType' object is not iterable
What does this mean???
below is my code for that function and also another one.... I'm only very new to this so I am getting so frustrated with myself and am finding the university is not helping me much at all...
below is some code. The first fuction is to simply return the average rating of the video and a count.... I thought I did this right as when I create a separate shell that links to the database it provides the average and the count. (number of ratings added to the database) But when I run the the test script it comes up with an error message saying
line 145, in test_average_ra ting
(avg, count) = util.average_ra ting(vid)
TypeError: 'NoneType' object is not iterable
What does this mean???
below is my code for that function and also another one.... I'm only very new to this so I am getting so frustrated with myself and am finding the university is not helping me much at all...
Code:
def average_rating(video_id): """Return the average rating for this video and the number of votes as a tuple (avg, count)""" con = connect() cur = con.cursor() average = cur.execute("select AVG(rating), count(rating) from ratings") for ratings in average: print ratings def add_rating(video_id, email, rating, comment): """Add a rating for a given video and user email. If the video or user doesn't exist, or if the rating is outside of the range 1-5, raise an exception of type WebappError with a message that can be shown to the user. """ con = connect() cur = conn.cursor() cur.execute("INSERT INTO ratings(video, email, rating, comment) VALUES ('?','?','?','?')") conn.commit()
Comment