随机导入 进口时间
RollAgain =“是”
而RollAgain ==“是”或RollAgain ==“y”:
DiceThrows = int(input('How many Dice would you like to throw: '))
DiceType = int(input ('How many sides are on your dice: '))
throw = 0
print 'Rolling the Dice...'
for throw in range (DiceThrows):
time.sleep(1)
print(random.randint(1,DiceType)), # Comma prints number on same line
How do you add them on the same line?
RollAgain = raw_input("Would you like to roll again? ")
答案 0 :(得分:0)
您可以使用sys.stdout.write
代替print
来执行此操作。
import random
import time
import sys
RollAgain = "yes"
while RollAgain == "yes" or RollAgain == "y":
DiceThrows = int(input('How many Dice would you like to throw: '))
DiceType = int(input ('How many sides are on your dice: '))
throw = 0
print('Rolling the Dice...')
sum = 0
for throw in range (DiceThrows):
time.sleep(1)
no = random.randint(1,DiceType)
sum += no
sys.stdout.write(str(no) + " ")
print("= %d" %sum)
RollAgain = raw_input("Would you like to roll again? ")