我正在製作一個Candy Box版本。這是到目前爲止我的代碼用另一個文本替換一行文本(Python)
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.
然後它會變成:如果您的控制檯理解ANSI控制碼
You have 4 candies.
您可能對這篇文章感興趣:http://stackoverflow.com/questions/6169217/replace-console-outp ut-in-python – karthikr