Ejemplo n.º 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!
from ex_2_task_1 import is_valid_email_address as is_valid

gave_up = False
attempts_left = 3

# your code - start
email = input("Email Address: ")  # initialize email
err_code, err_str = is_valid(email)  # check validity
while err_code is not None:  # try until there's no error
    print(email, "is invalid!", err_str)  #

    # use an attempt
    attempts_left -= 1
    if attempts_left == 0:  # if there's no attempts left, give up and break
        gave_up = True
        print("No attempts left.")
        break

    print(f"Try again, {attempts_left} attempts left.")
    email = input("Email Address: ")
    err_code, err_str = is_valid(email)  # check validity

# your code - end
Ejemplo n.º 2
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!
from ex_2_task_1 import is_valid_email_address as is_valid

gave_up = False  # variable for when total attmepts run out
attempts_left = 3  # set total number of attempts allowed

# your code - start
while True:
    email = input("please enter an email address:")  # user enters email
    r, err_str = is_valid(email)

    if r == None:  # no error messages
        print(email, "is valid!Good job.")  # valid email
        break  # jump out of loop

    # error happens
    attempts_left = attempts_left - 1  # lose an attempt

    # no attempts left - quit program
    if attempts_left == 0:
        gave_up = True
        print("Sorry - No attempts are left!")
        break  # quits the program and stops loop

    print(email, "is invalid!")  # tells invalid email
Ejemplo n.º 3
0
# 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!
from ex_2_task_1 import is_valid_email_address as is_valid

gave_up = False
attempts_left = 3

# your code - start
while True:
    email = input("email address?") # ask users to input email address
    code, error = is_valid(email) #call is_valid with the input email and store the results in code and error

    if code == None: #no error
        print(email, "is valid!")
        break #bail out
    
    # error

    attempts_left -= 1 #update the attempts_left

    # no attempts left - bail out 
    if attempts_left == 0:
        gave_up = True # set gave_up to true
        print("No attempts left, bailing out")
        break #bail out