Beispiel #1
0
# Optionally, you can use regex for all this!

# Once you're solved this, run some tests to show me that it works.
# Again, manually copy/paste the console output in a text file (results2.txt)

# import your function from the previous .py file as a module (you can abbreviate it)
# use ex_2_task_2 here instead once your function works!(I don't quite understand what do you mean by this comment)
from ex_2_task_1_solution import is_valid_email_address as is_valid

gave_up = False
attempts_left = 3

while attempts_left > 0:
    email = input("What's your email address?")
    r, err_str = is_valid(email)

    if r == None:
        print(email, "is valid!")
        break
    # error
    else:
        attempts_left -= 1
        print(email, "is invalid!")
        print("Reason:", err_str)
        if attempts_left > 0:
            print(f"Try again, {attempts_left} attempts left")
        else:
            print("No attempts left, bailing out")

# your code - end
Beispiel #2
0
    elif gave_up == True:
        attempts_left == 0
        print(is_valid(user_input), f'you have no attempts left.')
        break
    
    else: 
        attempts_left -= 1
        print(is_valid(user_input), f'you have {attempts_left} attempts remaining. Please try again.')
        #break 
'''

while not gave_up:
    user_input = input('Enter an email address you would like to create:')
    if is_valid(
            user_input
    )[0] is None:  #showing only first position of None from the function created
        print(f'Congrats, your new email address is {user_input}')
        break
    else:
        attempts_left -= 1
        print(is_valid(user_input),
              f'you have {attempts_left} attempts remaining.')
        if attempts_left == 0:
            print(f'you have no attempts left.')
            gave_up = True
'''
while True:
    email = input("email address?")
    r, err_str = is_valid(email)