0
print ('hello, welcome to our bar')
age = int(input("What is your age"))

if age < 21:
    print ('*kicks your ass out of bar*')
else:
    print("come on in") 

I am able to run the code and have it ask for a number, once you enter the number under the number the desired output comes out. What is want is for instead of the output to look like

hello, welcome to our bar
What is your age25
come on in

I want it to just look like

come on in

very new so sorry if this is super simple I have been searching for someone who has previously asked this but none of the code I'm finding works

  • 1
    Are you looking for `sys.stdout.flush()`? (Python 3: `print(text, flush=True)`) – Lab Apr 02 '21 at 04:51
  • try `clear = lambda : os.system('cls')` after age input –  Apr 02 '21 at 04:52
  • Does this answer your question? [How to clear the interpreter console?](https://stackoverflow.com/questions/517970/how-to-clear-the-interpreter-console) – OldWizard007 Apr 02 '21 at 04:56
  • 1
    i think he/she/they/it don't want the input to be visible and just want the output to be printed. – OldWizard007 Apr 02 '21 at 04:57

2 Answers2

2

You can just clear the screen using the os module.

import os 

os.system('clear')

Use this code before printing "come on in" and import os in the beginning of your code like:

import os

print ('hello, welcome to our bar')
age = int(input("What is your age"))

if age < 21:
    print ('*kicks your ass out of bar*')
else:
    os.system('clear')
    print("come on in") 
OldWizard007
  • 370
  • 1
  • 8
0

You've to just use os python module.

Though there're two ways in which you can do it i.e., using function or method and directly using os module.

  • Using function or method

import os

print ('hello, welcome to our bar \n')
age = int(input("What is your age \n"))

def ClearScreen():
   # for mac and linux(here, os.name is 'posix')
   if os.name == 'posix':
      _ = os.system('clear')
   else:
      # for windows platfrom
      _ = os.system('cls')

if age < 21:
    ClearScreen()
    print ('*kicks your ass out of bar* \n')
     
else:
    ClearScreen()
    print("come on in \n")
  • Using os module directly.

import os

print ('hello, welcome to our bar \n')
age = int(input("What is your age \n"))

if age < 21:
    if os.name == 'posix':
      _ = os.system('clear')
    else:
      # for windows platfrom
      _ = os.system('cls')
    print ('*kicks your ass out of bar* \n')
     
else:
    if os.name == 'posix':
      _ = os.system('clear')
    else:
      # for windows platfrom
      _ = os.system('cls')
    print("come on in \n")