在 Python 中制作一个简单的 "Loading Bar" 3
Make a simple "Loading Bar" in Python 3
我只是在闲逛,我想打印一张 "Loading Bar"。我希望它说 "Calculating..."
,每个 .
在 1 秒后添加到 Calculating
。我使用 end=''
将点保持在同一行上,但不是等待 1 秒然后添加每个句点,而是等待 3 秒并打印 "Calculating..."
。
import time
dividend = input("Enter number to be divided: ")
divisor = input("Enter divisor: ")
dividend = float(dividend)
divisor = float(divisor)
wholenum = dividend // divisor
remainder = dividend % divisor
print("Calculating", end='')
time.sleep(1)
print(".", end='')
time.sleep(1)
print(".", end='')
time.sleep(1)
print(".")
time.sleep(1)
print("The quotient is:", wholenum)
print("The remainder is:", remainder)
在打印语句中使用 flush=True
。
print(".", end='', flush=True)
我只是在闲逛,我想打印一张 "Loading Bar"。我希望它说 "Calculating..."
,每个 .
在 1 秒后添加到 Calculating
。我使用 end=''
将点保持在同一行上,但不是等待 1 秒然后添加每个句点,而是等待 3 秒并打印 "Calculating..."
。
import time
dividend = input("Enter number to be divided: ")
divisor = input("Enter divisor: ")
dividend = float(dividend)
divisor = float(divisor)
wholenum = dividend // divisor
remainder = dividend % divisor
print("Calculating", end='')
time.sleep(1)
print(".", end='')
time.sleep(1)
print(".", end='')
time.sleep(1)
print(".")
time.sleep(1)
print("The quotient is:", wholenum)
print("The remainder is:", remainder)
在打印语句中使用 flush=True
。
print(".", end='', flush=True)