【发布时间】:2020-03-04 18:01:11
【问题描述】:
为什么下面的代码中有一个+1?
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)
我能够运行此代码,但我不知道为什么会出现 +1。
【问题讨论】:
-
比较
list(range(die.num_sides))和list(range(1, die.num_sides+1))。
标签: python data-visualization data-analysis pygal