1

Why is there a +1 in the code below?

from die import Die
#from the file die.py import the Class Die

# create a D6.
die = Die()

# make some rolls, and store results in a list.
results = []
for roll_num in range(100):
    result = die.roll()# file die.py and function roll in that file.
    results.append(result) #adding to results every time that a die roll. die.roll()


# Analyze the results.

frequencies = []
for value in range(1,die.num_sides+1):
    frequency = results.count(value)
    frequencies.append(frequency)



print(frequencies)

I am able to run this code, but I don't know why that +1 is there.

rpanai
  • 12,515
  • 2
  • 42
  • 64
Lucas Batista
  • 143
  • 1
  • 5

1 Answers1

0

from the example in the documentation

>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Brandon Henry
  • 3,632
  • 2
  • 25
  • 30