how to wait and print on the same line python
python, vpython
Solution
Try this:
import time
for i in range(5, 0, -1):
print i, # print in the same line by adding a "," at the end
time.sleep(1)
if i == 1:
print 'Blastoff!'
It'll work as expected:
5 4 3 2 1 Blastoff!
EDIT
... Or if you want to print all without spaces (which is not clearly stated in the question):
import time
from __future__ import print_function # not necessary if using Python 3.x
for i in range(5, 0, -1):
print(i, end="")
time.sleep(1)
if i == 1:
print(' Blastoff!')
The above will print:
54321 Blastoff!
Problem
ok, so I am doing this tiny countdown function in vpython, the way I am doing it now is ``` import time print "5" time.sleep(1) print "4" time.sleep(1) print "3" time.sleep(1) print "2" time.sleep(1) print "1" time.sleep(1) print "0" time.sleep(1) print "blastoff" ``` Of course, this is not actually my code, but it demonstrates it fairly well. so what I want to do is instead of printing it 5 4 3 2 1 Blastoff I want 54321 Blastoff on the same line. How would I wait for a second and print the charecter on the same line. please let me know, It would be a great help