我想顯示每個可能的隨機數是通過在數字旁邊有一個符號生成的。但它把符號在新行這樣的數字之下:在python中顯示隨機數頻率
Dice rolled:
You rolled 2 and 4
Roll again [y|n]? n
Number Frequency:
1
2
x
3
4
x
5
6
如何我可以使它顯示在數字旁邊的同一行的符號?
import random
diceCount = [0,0,0,0,0,0,0]
roll='y'
while roll=='y':
die1=random.randint(1,6)
die2=random.randint(1,6)
diceCount[die1] = diceCount[die1] + 1
diceCount[die2] = diceCount[die2] + 1
print('Dice rolled:')
print('You rolled',die1,'and',die2)
if roll=='y':
roll=input('\nRoll again [y|n]? ')
while roll!='y' and roll!='n':
roll=input("Please enter either 'y' or 'n': ")
if roll=='n':
print('\nFace Freqeuncy:')
index=1
while (index<len(diceCount)):
print(index)
for number in range (diceCount[index]):
print(' x')
index+=1
這將不利於OP。那麼所有未計數的值也將在同一行上。 – 2013-04-28 08:58:59