我想显示通过在数字旁边有一个符号来生成每个可能的随机数的次数。但它将符号放在数字下方的新行上,如下所示:
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