Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6892961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:35:58+00:00 2026-05-27T06:35:58+00:00

querytimes = SELECT video_id, COUNT(src_ip) FROM video GROUP BY video_id ORDER BY COUNT(src_ip) DESC

  • 0
querytimes = "SELECT video_id, COUNT(src_ip) FROM video GROUP BY video_id ORDER BY COUNT(src_ip) DESC"
cur.execute (querytimes)
dltimes = cur.fetchall()
for row in dltimes:

    videoid = str(row [0])
    downloadtimes = int(str(row [1]))
    x.append(rank)
    rank = rank + 1 
    y.append(downloadtimes)
    v.append(videoid)


counter = dict(zip(v, y))
for n in xrange(1, max(counter.itervalues()) + 1):
    perc = 100. / sum(1 for nb in counter.itervalues() if nb == n) / len(counter)
if perc:
   print '%.f%% videos have been downloaded %d times' % (perc, n)

This is my code. At first I read data from a database, then put videoid and downloadtimes into a dictionary, and do some calculation, but I got the following error:

perc = 100. / sum(1 for nb in counter.itervalues() if nb == n) / len(counter)
ZeroDivisionError: float division

Can anyone help a bit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:35:59+00:00Added an answer on May 27, 2026 at 6:35 am

    Have you checked that your counter dictionary has at least one value that matches the nb == n condition? To me it seems like either your sum or your len return 0 as a result…

    Check this out:

    >>> n = 3
    >>> counter = {'a': 1}
    >>> 100. / sum(1 for nb in counter.itervalues() if nb == n) / len(counter) 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ZeroDivisionError: float division by zero
    >>> counter = {'a': 3}
    >>> 100. / sum(1 for nb in counter.itervalues() if nb == n) / len(counter) 
    100.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT COUNT(*) FROM song AS s JOIN user AS u ON(u.user_id = s.user_id) WHERE
I have some demanding mysql queries that have to select same frequently updated datasets
I wanna get the Timedate value from another page using request.querystring and then use
If I have something like: CREATE INDEX idx_myTable_field_x ON myTable USING btree (field_x); SELECT
$output .=<keyword>.$_POST['keyword'].</keyword><name>.$row['url'].</name><occur>.$row['occurrences'].</occur><queryTime>.(substr($end_time-$start_time,0,5)).</queryTime>; } I want to check in Flex, if the value of name
$output = <loginsuccess>; for( $i = 1; $row = mysql_fetch_array($result); $i++ ) { $output
I have a Sql-Server-2008 database that I am querying from on the regular that
I currently have a closure table used for hierarchical data that has 5 million
We are having performance issues on our web app during peak times, which is
I am planning to implement database search through a website - I know there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.