Debugging codes

Can someone please debug my code?

Welcome, @calebpyung, to Replit Ask!

First off, what error are you getting so we can identify the problem?

1 Like

The screen should clear but it doesn’t

1 Like
def clear () :
 if choice.lower() == "clear":
   os.system('cls' if == 'nt' else 'clear')

Why do you have an if statement if you are already checking if you typed clear in at the bottom with this code?:

choice = input("Clear Screen?: ")
if choice.lower() == "clear":

Also I’m pretty sure you can just do os.system('cls') instead of os.system('cls' if == 'nt' else 'clear')

1 Like

Are you also getting any errors in the console itself?

It should repeat the clear function after I type clear two times But, when I type it a third time I get this : sh: 1: cls: not found, In the console

That in itself should be the issue, choice shouldn’t be defined there.


How can I remove it?

Since Replit runs Linux, just swapping your clear function for:

def clear():

Should work.

1 Like

That’s the opposite way around :upside_down_face:, windows uses cls while Linux uses clear.


Now the program is suppose to repeat infinitely but when I type clear two times the program stops

Ohh, that makes sense. I mean I don’t use Linux so no wonder I didn’t know

No it’s basically saying if it’s a Windows OS (which it’s not), then do cls. But since it’s not it will do clear. Clear is the right one but is still inefficient. Use from replit import clear

My bad, didn’t see FP’s reply


It’s not that the clear command itself is inefficient; rather, os.system is slow.

hope I used ; right

1 Like