Python Python Basics (2015) Letter Game App Letter Game Refinement

Jen Farrant
Jen Farrant
6,892 Points

the clear screen doesn't work.

I cannot get the clear screen function to work. I'm on a mac, and I've tried it the code in Idle and Thonny. It's not my code that's the issue, I've downloaded Kenny's code (which I presume works fine!) and I can't get that to work in Thonny or Idle either.

It's not just this section of the course, it is anytime that I use the clear function - it just doesn't work. I'm using the code for both mac and windows in my coding.

def clear():
    if os.name == 'nt':
        os.system('cls')
    else:
        os.system('clear')

and as I said, even Kenny's code doesn't work, so I'm confident I haven't made an error

Any suggestions?

2 Answers

Viraj Deshaval
Viraj Deshaval
4,585 Points

It will not work in IDLE or Thonny or any other python work ground because "os" library let's us use functionality on operating system level. To perform similar kind of thing in IDLE you can try this as below:

def clear(): print("\n" * 150) clear() print("Hello Treehouse")```

I hope I answered your query. Please let me know if you require any example.

Jen Farrant
Jen Farrant
6,892 Points

I did not know that.... thank you for letting me know, I can stop being extremely frustrated now!

Viraj Deshaval
Viraj Deshaval
4,585 Points

Hi Jen, Thanks for reaching out to community. You need to import os module in order to use os functions. Just write "import os" without quotes of course and try it should work.

Jen Farrant
Jen Farrant
6,892 Points

sorry, should have been clearer - I'm already doing that further up the screen