|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- from random import randint
- def dice():
- a = randint(1, 6)
- b = randint(1, 6)
- c = a + b
- return c
- def main():
- frequency = {2: 2.78, 3: 5.56, 4: 8.33, 5: 11.11, 6: 13.89, 7: 16.67,
- 8: 13.89, 9: 11.11, 10: 8.33, 11: 5.56, 12: 2.78}
- true_frequency = {2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0,
- 8: 0, 9: 0, 10: 0, 11: 0, 12: 0}
- time = int(input('please enter the times:'))
- for i in range(0, time):
- if frequency.keys() == dice():
- true_frequency[dice()] += 1
- time = float(time)
- for num, times in true_frequency:
- true_frequency[num] = times / time
- if __name__ == '__main__':
- main()
复制代码
在执行这个程序的时候,会报错TypeError: cannot unpack non-iterable int object,不知道是什么原因,请大神指点。
- for num , times in true_frequency :
复制代码
改为:
- for num , times in true_frequency . items() :
复制代码
|
|