-1

OK, so I am currently messing around coding hangman in python and was wondering if I can clear what it says in the python shell as I don't just wan't the person to read the word.

import time
keyword = input(" Please enter the word you want the person to guess")
lives = int(input("How many lives would you like to have?"))
print ("There are ", len(keyword), "letters in the word")

time.sleep(2)

guess = input("please enter your guess")

I would like to remove all the text in the shell.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • show us the code.....why is the word visible at the beginning? – depperm Jun 06 '17 at 17:12
  • 1
    Are you asking about [clearing the entire shell](https://stackoverflow.com/questions/517970/how-to-clear-the-interpreter-console) or clearing just specific text displayed? As @depperm mentioned, please share some code or otherwise be more clear/specific about what you're asking for. – Knowledge Cube Jun 06 '17 at 17:14

4 Answers4

1

if you are a windows user use this:

import os
os.system("cls")

Mac/linux then :

import os
os.system("clear")
Kishy Nivas
  • 663
  • 8
  • 21
0

Try this:

import subprocess
import time

tmp=subprocess.call('clear', shell=True) # 'cls' in windows
keyword = input(" Please enter the word you want the person to guess")
lives = int(input("How many lives would you like to have?"))
print ("There are ", len(keyword), "letters in the word")

time.sleep(2)

Save the code in a python file. Then execute it from shell.

akhilsp
  • 1,063
  • 2
  • 13
  • 26
0
print("\n" * 100)

There is no other way to do it then to just spam the console.

Elias Konrad
  • 108
  • 1
  • 9
0

os.system("cls") for windows or os.system("clear") for mac/linux.

Then put that line of code where you wish for the program to delete all the text in the shell.

Dorilds
  • 418
  • 1
  • 7
  • 15