0

I am kind of bad at all this programming stuff and i need help.

I want my code to print something like hello world and then after lets say 1 second
delete that text and replace it with how are you? I have tried various thing like 'clear' and '/b' but nothing is working, if you can help that would be amazing.

import time
print('hello world')
time.sleep(3)
#The text deleting code here...
print('how are you?')
Austin
  • 24,608
  • 4
  • 20
  • 43

1 Answers1

1

Use end parameter of print(). By default, it's assigned \n. Instead, use a carriage return which is used to move the carriage back to the left side (beginning) of the current line.

import time
print('hello world', end='\r')
time.sleep(3)
#The text deleting code here...
print('how are you?')
Austin
  • 24,608
  • 4
  • 20
  • 43
  • Thank you for the contribution but when i ran it in Idle it didn't work – PyProgrammerNoob Jun 23 '18 at 16:03
  • Unfortunately, Python idle does not support `\r`. Read about it [here](https://bugs.python.org/issue23220). You could run this code on command prompt and get desired output. – Austin Jun 23 '18 at 16:23