Python Forum
How do you add the results together each time a function is called?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you add the results together each time a function is called?
#4
(Jul-31-2019, 01:42 AM)ichabod801 Wrote: First...

I don't understand how you're using num in

for num in range(1000):
    counts[random.randint(1, 10)] += 1
Num doesn't appear in the indented line.

(Jul-31-2019, 03:22 AM)scidam Wrote: Did you consider using numpy to solve this problem? if you use numpy, you can easily generate array of random numbers and then count each number, something like this:

from collections import Counter
import numpy as np
Counter(np.random.randint(0, 10, 1000))

Thanks, my data-scientist friend told me about that. I just wanted to see if I could do it without importing any more modules.
Reply


Messages In This Thread
RE: How do you add the results together each time a function is called? - by Exsul - Aug-08-2019, 11:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple variable inputs when only one is called for ChrisDall 2 514 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,369 Aug-06-2023, 02:29 PM
Last Post: deanhystad
Bug New to coding, Using the zip() function to create Diret and getting weird results Shagamatula 6 1,488 Apr-09-2023, 02:35 PM
Last Post: Shagamatula
  Couldn't install a go-game called dlgo Nomamesse 14 3,218 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  how can a function find the name by which it is called? Skaperen 18 3,564 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  function with 'self' input parameter errors out with and without 'self' called dford 12 3,196 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  time function does not work tester_V 4 3,091 Oct-17-2021, 05:48 PM
Last Post: tester_V
  How to print results of asyncio websockets at the same time? codingmonster 0 1,784 Jun-04-2021, 01:48 PM
Last Post: codingmonster
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,307 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Can you end the Time.sleep function boier96 9 9,584 Jan-16-2021, 10:09 PM
Last Post: Serafim

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020