0

I present the following example code (in python), where I want to overwrite the error messages, so that it does re-appear in the same terminal space (& not in the following terminal space) if the user inputs an invalid value (single or many times)? Kindly help.

# bug condition (Numeric character value)
num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
tracker = 0

while True:
    value = input("\n\t Enter the value - ")

    for num in num_list:
        if num in value:  # numeric character is present
            print("\n\t\t Error: Invalid value.")
            print("\t\t  Note - Make sure that the entered value does not contain numeric characters.")
            tracker += 1
            break

    if tracker >= 1:  # if the user inputted invalid value (one or more times)
        continue  # re-input again
    else:  # if the input is valid
        break  # break & proceed forward

# the end -------------------------------------
  • Does this apply to you ? https://stackoverflow.com/questions/9949887/delete-characters-in-python-printed-line – Dams Mar 30 '22 at 09:47
  • Yes Dams, not entirely though. As I want two things to happen (when a value is invalid)- 1) The Input field/space should be reset/cleared as the user hits the Enter key, ready for re-input. 2) The Error message should be displayed, but if the user again inputs invalid value, then the same Error message should appear in the same place, not in the next terminal/console space, while the previous message still displays, making the whole output a long list of grocery items. Anyways, thanks for asking. – Sahil Jaswal Mar 30 '22 at 10:15

0 Answers0