我正在尝试用编写代码来记录用户玩骰子游戏“中间”的结果,然后在游戏结束时打印滚动的统计数据,所以我想要打印的基本上是这样的。
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发布于 2013-05-07 14:22:27
你可以用这种方式打印整条线:
for i, val in enumerate(dieCount[1:], 1):
print('{} {}'.format(i, '*' * val))发布于 2013-05-07 14:27:57
第一个打印(索引)似乎是自动添加后的换行符。试着把它写成你打印*的方式:
print(index, end='')发布于 2013-05-07 14:21:41
试试这个:
while index < len(dieCount):
print(index,end ="")
for n in range(dieCount[index]):
print('*', end='')
print()
index = index + 1https://stackoverflow.com/questions/16421353
复制相似问题