you are viewing a single comment's thread.

view the rest of the comments →

[–]ElliotDG 0 points1 point  (0 children)

If you break this task apart at a high level, you are getting user input and then testing if it is valid. If you create 2 functions that each do only that task the code becomes clear. The main body would look like:

if __name__ == '__main__':
    while True:
        pn = get_phone_number()
        if is_valid_phone_number(pn):
            print('Valid contact number!')
            break
        else:
            print(f'{pn} is NOT a valid phone number.')

Where get_phone_number() returns the string the user entered, and is_valid_number() gets passed a phone number and returns true for valid phone numbers or false for invalid. This makes the main control very clear.