Python: Clear the screen or terminal
Python Basic: Exercise-99 with Solution
Clear Terminal
Write a Python program to clear the screen or terminal.
Sample Solution:
Python Code:
# Import the 'os' and 'time' modules to work with system commands and time-related functions, respectively.
import os
import time
# Execute the 'ls' command to list the contents of the current directory.
os.system("ls")
# Pause the program's execution for 2 seconds.
time.sleep(2)
# Clear the terminal screen. (This comment is not entirely accurate; 'os.system('clear')' is used to clear the terminal screen.)
os.system('clear')
Flowchart:
Python Code Editor:
Previous: Write a Python program to get the system time.
Next: Write a Python program to get the name of the host on which the routine is running.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-basic-exercise-99.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics