Hi everyone, below is my code and the results of my guided project, is the figure correct? More importantly how to you verify if what you have coded is correct??? Appreciate any guidance. Thanks!
# Filter posts with 'ask hn' and 'show hn' into a list
ask_posts = []
show_posts = []
other_posts = []
for row in hn:
title = row[1]
title = title.lower()
if title.startswith('ask hn'):
ask_posts.append(row)
elif title.startswith('show hn'):
show_posts.append(row)
else:
other_posts.append(row)
# Calculate the average number of ask posts comments
total_ask_comments = 0
for row in ask_posts:
comments = row[4]
comments = int(comments)
total_ask_comments += comments
avg_ask_comments = total_ask_comments/len(hn)
print(avg_ask_comments)
1.2180597014925374
# Calculate the average number of show posts comments
total_show_comments = 0
for row in show_posts:
comments = row[4]
comments = int(comments)
total_show_comments += comments
avg_show_comments = total_show_comments / len(hn)
print (avg_show_comments)
0.5964179104477612