Feb-21-2021, 04:47 PM
(This post was last modified: Feb-21-2021, 04:47 PM by Gribouillis.)
Every time the number
num
is produced by the random generator, the program adds 1 to the count frequency[num]
which counts the number of times this particular number was generated. The test is necessary because if the key num
is not already in the dictionary, the line frequency[num] = frequency[num] + 1
would raise an exception. Initialy the dictionary is empty and contains no key.