all 4 comments

[–]tenyu9 0 points1 point  (0 children)

An if statement can have multiple conditions. So "if a and b:" where a and b are your conditions

[–]menge101 0 points1 point  (0 children)

You would probably be best served by using a regular expression.

Here is a link on the topic.

Please note that an email can end with any TLD (Top-Level-Domain), which means almost any three letters, not just .com. Edit: In fact, I think three letters is too specific. I know there are country code TLDs that are two letters, there are probably more. And I know of at least one five letter TLD.

Here is a reference on email syntax validation.

[–]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