-1

I'm coding a game like a quiz game in "Pycharm", and I want the console to be cleared after each question is asked. In Replit there is a built in function as "clear()" which allows you to clear the console at any point in your code. From what I know, in python on windows "cls" clears the console but manually and it's not a function that we can use in our codes. can anyone help me with that?

I've tried:

import os def clear(): os.system('cls')

and

import os clear = lambda: os.system('cls')

yet it doesn't work and only shows a broken emoji.

Amir Gh
  • 1
  • 2
  • 1
    Does this answer your question? [Clear/overwrite standard output in Python](https://stackoverflow.com/questions/37071230/clear-overwrite-standard-output-in-python) – Fran Arenas Aug 16 '22 at 12:24
  • You can run system commands like "cls" in python using the `os` library, allowing you to clear the screen in this way. See https://stackoverflow.com/a/518007. – Peter Warrington Aug 16 '22 at 12:30

1 Answers1

1

https://www.tutorialspoint.com/how-to-clear-python-shell i guess that should help.

from os import system, name
from time import sleep
def clear():
      _ = system('cls')

print(“Hi Learner!!”)
sleep(5)
clear()
turtelian
  • 31
  • 4