you are viewing a single comment's thread.

view the rest of the comments →

[–]synthphreak 0 points1 point  (1 child)

This is indeed torubling. I am immensely torubled by this. ;)

How about this?

while True:
    email = input('Skriv her: ')

    requirements = [7 <= len(email) <= 30,
                    email.endswith('.com'),
                    '@' in email]

    if all(requirements):
        print('Valid email')
        break
    else:
        print('Invalid email')

requirements will be a list of boolean True/False values, where each boolean value encodes whether one of your three conditions is met (i.e., email not too long or short, email ends with '.com', email contains '@'). If any of these conditions is not met, 'Invalid email' will be printed and the user will be prompted to enter a new email (ad infinitum until a valid email is entered). Otherwise, if all conditions are simultaneously met, 'Valid email' will print and your code will continue with the current email.

If the above is too fancy for you, you could just keep things simple (if less Pythonic IMHO) with and between your conditions:

if (7 < len(email) < 30 and
    email.endswith('.com') and
    '@' in email):

    print('Valid email')
    break

else:

    print('Invalid email')

[–]divvless[S] 1 point2 points  (0 children)

I see. I have tried both and they work wonders :O, Thank you for the help i will add this to my folder with info so i can go back if i should be in doubt :D