【发布时间】:2020-01-15 10:12:57
【问题描述】:
我正在尝试编写输出如下内容的数字骰子:
1: 1 of 36 卷 2.7777%
2:36 卷中的 2 卷 5.5555%
3:36 卷中的 3 卷 8.3333%
不太清楚该怎么做,但这是我的代码。
import random
import colorama
from colorama import Fore, Style
random.seed()
ROLLED = {i: 0 for i in range(1, 7)}
ITERATIONS = int(input(Fore.LIGHTRED_EX + "How many times would you like to roll the dice?\n"))
Style.RESET_ALL
def probability():
print(Fore.LIGHTWHITE_EX+"Calculation of probability:")
for key, count in ROLLED.items():
print("\t{}: {:.2f}".format(key, count*100./ITERATIONS*1.))
for _ in range(ITERATIONS):#for the inputted range for the iterations
ROLLED[random.randint(1, 6)] += 1
probability()
我不知道该怎么做。可以使用帮助/提示来找出答案。
【问题讨论】:
-
现在有什么作用?另外你还没有导入
random,所以这不会运行
标签: python python-3.x dice