替换多行控制台文本Python 2.7

时间:2016-11-08 16:46:51

标签: python python-2.7

所以我正在创建一个老虎机作为一个有趣和学习的小项目,我想知道是否有办法在控制台中替换多行文本。我有它替换一行,但我希望能够打印三行,然后顶部替换为中间,然后中间与底部,并继续直到循环完成。我仍然是初学者,所以如果你有任何提示,或者请随意批评我的代码。谢谢

import sys
import time
from random import randint

slot_possibilities = ["  Star ","  Moon ","  Sun! "," Monkey"]
wait_time = 15

print "--------------------------------"
print "|--------Monkey-----Slots------|"
print "|------------------------------|"
while wait_time != 0 :
    x = randint(0,3)
    y = randint(0,3)
    z = randint(0,3)
    sys.stdout.write("\r|" + slot_possibilities[x] + " || " + slot_possibilities[y] + " || "+ slot_possibilities[z] + " |")
    time.sleep(1)
    wait_time -= 1
print
print

0 个答案:

没有答案