0

I'm just messing around and I want to make a "Loading Bar" print. I want it to say "Calculating..." with each . adding to Calculating after 1 second each. I'm using end='' to keep the dots on the same line but instead of waiting 1 second and then adding each period, it waits 3 seconds and prints "Calculating..." altogether.

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)
imn1698
  • 11
  • 2
  • Does this answer your question? [Python to print out status bar and percentage](https://stackoverflow.com/questions/3002085/python-to-print-out-status-bar-and-percentage) – Professor Nuke Jun 12 '20 at 22:25
  • also this https://stackoverflow.com/questions/3160699/python-progress-bar – Tibebes. M Jun 12 '20 at 22:26
  • Just ensure that any progress bar is only displayed if you are writing to a terminal device (test using `if sys.stdout.isatty():` ) - or one day you will deploy your application with output redirected to a log file and your log file will be full of useless dots. – alani Jun 12 '20 at 22:35

1 Answers1

0

Use flush=True in your print statements.

print(".", end='', flush=True)
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17