【问题标题】:Rolling dice with pygal用 pygal 掷骰子
【发布时间】: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


【解决方案1】:

来自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]

【讨论】:

    猜你喜欢
    • 2018-09-08
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 2015-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多