【发布时间】:2015-01-22 17:08:47
【问题描述】:
我写了一个简单的程序来计算掷骰子的平均结果(毫无意义,但你必须从某个地方开始;P):
import random, time
from random import randrange
count = 0
total = 0
one_count = 0
for x in range(10000000):
random = randrange(1,7)
count = count + 1
total = total + random
average = total / count
percentage = one_count / count * 100
if random == 1:
one_count = one_count + 1
print("the percentage of ones occurring is", percentage, "and the average outcome is", average)
# time.sleep(1)
为了清理它,我希望输出覆盖上一行。我尝试了所有我能找到的东西,但我唯一能做到的就是打印到同一行而不删除以前的内容,方法是将最后一行更改为:
print("the percentage of ones occuring is", percentage, "and the average outcome is", average, "/// ", end="")
哪个输出:
the percentage of ones occuring is 0.0 and the average outcome is 4.0 /// the percentage of ones occuring is 0.0 and the average outcome is 4.5 /// the percentage of ones occuring is 0.0 and the average outcome is 3.6666666666666665 ///
有什么想法吗?
【问题讨论】:
标签: python python-3.x command-prompt overwrite