0

enter image description here

This is the, I am trying to validate a user input whether it is a number or in a given range, but every time it's not in the range or its a word, it creates a new cell to input a number, want to clear the history of previous cells, how?

def validiating_user():
    accepted_range = range(0,10)
    within_ranges = False
    r = 'abcd'
    while r.isdigit() == False or within_ranges == False:
        r = input('Plase input a number(0-10): ')
        if r.isdigit() == False:
            print('Please enter a number,not words')
        if r.isdigit() == True:
            if int(r) in accepted_range:
                within_ranges = True
            else:
                print('Please enter a number in range(0-10)')

    return int(r)

print(validiating_user())
Barmar
  • 741,623
  • 53
  • 500
  • 612
Nowshad
  • 29
  • 4
  • There are no cells. You're just writing messages and prompts sequentially to the terminal. If you want a more structured user interface, use something like `TKinter`. – Barmar Feb 04 '21 at 07:48
  • does this answer your question: https://stackoverflow.com/questions/4810537/how-to-clear-the-screen-in-python? – Krishna Chaurasia Feb 04 '21 at 07:48
  • How about this? https://stackoverflow.com/questions/6169217/replace-console-output-in-python – Bojan Kogoj Feb 04 '21 at 07:57

2 Answers2

0

Try adding this to your code.

import os

os.system('clear') # Where you would like to have the screen cleared
stygarfield
  • 107
  • 9
0

Please try this

import os

clear_os = lambda: os.system('clear')
clear_os()
iamawesome
  • 652
  • 7
  • 15