我正在尝试在PYTHON中编写代码,该代码将记录用户玩骰子游戏“中间”的结果,然后在游戏结束时打印掷骰子的统计数据,所以基本上我想要打印的内容类似于这个
Game Summary
============
You played 3 Games:
|--> Games won: 0
|--> Games lost: 3
Dice Roll Stats:
Face Frequency
1
2 *
3
4 **
5 *
6 *
7
8 *
9 *
10 **
Thanks for playing!
每次滚动模具面时都会打印一个“*”,但是我一直以这样的方式结束..
Game Summary
============
You played a total of 3 games:
|--> Games won: 1
|--> Games lost: 2
Dice Roll Stats.
Face Frequency
1
2
** 3
4
5
* 6
* 7
**** 8
* 9
10
Thanks for playing!
所以我想要做的是将'*'垂直排列并与索引值(1、10)相同,而不是'*'总是放在索引值的前面。这是我的代码:)
die1 = random.randint(1, 10)
dieCount[die1] = dieCount[die1] + 1
die2 = random.randint(1, 10)
dieCount[die2] = dieCount[die2] + 1
die3 = random.randint(1, 10)
dieCount[die3] = dieCount[die3] + 1
dieCount = [0,0,0,0,0,0,0,0,0,0,0]
index = 1
while index < len(dieCount):
print(index)
for n in range(dieCount[index]):
print('*', end='')
index = index + 1