Reputation:
office_list = []
print("Type in your office supplies.\nEnter 'DONE' to print out your list.\n--------------------\n")
while True:
list = input("> ")
if list == 'DONE':
break
office_list.append(list)
print("Here is your list\n--------------------\n")
for ls in office_list:
print(ls)
I've been trying to find this online but seem to have trouble trying to find the correct vocabulary I believe.
What I am trying to make the program do is clear what I have written to make the list and then print the list. What happens in the program right now is it will have the words I typed on top of the list and print when I enter the word 'DONE'.
Upvotes: 1
Views: 163
Reputation: 1645
Using the os
module, you can run shell commands. To clear the console on Linux/macOS you can use the clear
command, on Windows there's cls
:
import os
import sys
def clear():
if sys.platform == 'windows':
os.system('cls')
else:
os.system('clear')
Upvotes: 1
Reputation: 2990
Just print enough newline characters like this:
print('\n' * 50)
It doesn't hurt to print out too many lines for a console application as this will all happen in a split second. This method is cross-platform and should work in nearly any environment.
The OS-level answers actually do the same thing, but the OS knows exactly how many lines to print. If you don't care about hiding the precise number of lines that are shown on the screen, just print out enough (within reason) to clear the console.
Upvotes: 0
Reputation: 78780
You can use the os
module. Under *nix, you can use os.system('clear')
or os.system('cls')
under Windows.
Upvotes: 2