Guided Project #2, 4/8

I’ve read through several threads about running into difficulty while calculating the average number of comments for ask_posts and am still unclear on how to solve this issue:
ValueError Traceback (most recent call last)
1 total_ask_comments = 0
2 for row in ask_posts:
----> 3 total_ask_comments += int(row[4])
4 print(total_ask_comments)

ValueError: invalid literal for int() with base 10: ‘h’

As per the suggestions in this post can you please provide a link to the mission you’re working on so that others have some context for your question? Also, please be sure to provide all your code that pertains to your problem. Specifically, how was ask_posts defined? I would like to know what data it contains to better be able to help you.

Without having a way to test out your code or knowing how some of your variables were instantiated, and just going by what you have provided here, I would guess that you’re getting this error because because row[4] inside your for loop contains values that int() does not know how to handle. It looks like one of the values contains the literal h which cannot be converted to an integer. I would suggest inspecting your data in row[4] to see if it is ready to be converted to integer values (ie it contains only numbers and no letters).

Let me know if this is the case and if not we can try something else to figure it out.

ask_posts =
show_posts =
other_posts =
for row in hn:
title = row[1].lower()
if title.startswith(‘ask hn’):
elif title.startswith(‘show hn’):
total_ask_comments = 0
for row in ask_posts:
total_ask_comments += int(row[4])

I figured it out by looking at someone else’s project! I was appending by title instead of row.