Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHussein Amr
2,461 PointsCan someone please explain why my clear function isn't working
import os
mylist = []
def clear_screen():
os.system = ("cls" if os.name == "nt" else "clear")
def help():
#print out instructions
print("type the stuff you want to add to the list")
print("""
type in 'DONE' when you are..
Enter 'HELP' when you need it
Enter 'SHOW' to show the added stuff""")
def add_to_list(new_item):
if len(mylist):
position = input("where should i add {} ?\n"
"press ENTER to just ass it to the end of the list\n"
"> ".format(new_item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
mylist.insert(position-1,new_item)
else:
mylist.append(new_item)
show_list()
def show_list():
clear_screen()
print("Here's everything on the list : ")
index = 1
for items in mylist :
print("{}. {}".format(index, items))
index += 1
print("-" * 15)
help()
while True:
new_item = input("> ")
#have an exit button
if new_item.upper() == 'DONE' or new_item.upper() == 'QUIT':
break
elif new_item.upper() == 'HELP' :
help()
continue
elif new_item.upper() == 'SHOW':
show_list()
continue
else:
add_to_list(new_item)
show_list()
3 Answers
Steven Parker
231,269 PointsLooks like you may have a stray symbol.
I suspect you don't want that equal-sign between "system" and the open parenthesis.
Daniel Maia
6,228 PointsWhen I use clear_screen() the function works but not on PyCharm on the run window. Is there a separate function for this?
I have been using print(" "*100) for now
Steven Parker
231,269 PointsThat clears the entire screen? I would have expected just a blank line. But this should do it (adjust value for the number of lines on your screen):
print("\n" * 80)
I'm not a PyCharm user, but perhaps someone who is can suggest a better solution.
Also, your question might be seen by more students if you create a new one. Comments added to an old question are only likely to be seen by the person who originally posted it and anyone who answered already.
Daniel Maia
6,228 PointsOk cool thank you :)
Hussein Amr
2,461 PointsHussein Amr
2,461 Pointsit worked :D thanks