我在做一个糖果盒的版本。这是我目前的密码
import time
print("Candy box")
candy = 0
while True:
time.sleep(1)
candy += 1
print("You have ", candy, " candies.")
问题是,当我想更新最后一行时,它会一行接一行地输出许多行。示例:
而不是:
You have 3 candies.
You have 4 candies.
You have 5 candies.
它将是:
You have 3 candies.
然后它会变成:
You have 4 candies.
如果您的控制台理解ANSI控制代码,则可以使用以下命令:
如果您的控制台不理解ANSI,请用控制台需要的相应控制代码替换
CSI F
和CSI J
。你知道吗更简单的版本(IMO)
使用
'\b'
返回并重新编写整行,从而给人一种更新的感觉您也可以尝试以下方法
相关问题 更多 >
编程相关推荐