1

Develop a python script to check whether a given input email id (in the form of string) is a valid email id or not without using built-in functions and regular expressions. Valid email addresses must follow these rules:

a. It must have the username@websitename.extension format type.

b. The username can only contain letters, digits and underscores.

c. The website name can only have letters and digits.

d. The maximum length of the extension is three characters.

so i did this

def p(n):
    a,b=n.split("@")
    c,d=b.split(".")
    # print(n,a,c,d)

    # a=username ,c=website,d=com
    a=list(a)
    c=list(c)
    d=list(d)

    print(a,c,d)
    alp="qwertyuiopasdfghjklzxcvbnm"
    g=list(alp)
    l=["_"]
    m=[1,2,3,4,5,6,7,8,9,0]
    m=list(m)
    print(g,l,m)
    for i in range(len(a)):
        if a[i] not in g or l or m:
            print("invalid ")
            return
    for i in range(len(c)):
        if c[i] not in g or m:
            print("invalid")
            return
    for i in range(len(d)): 
        if d[i] not in g or len(c)!=3:
            print("invalid")
            return
    print("valid")



n=input()
p(n)


all i get as output is invalid. what did i do wrong?

some suggested me to make some changes

def p(n):
    a,b=n.split("@")
    c,d=b.split(".")
    # print(n,a,c,d)

    # a=username ,c=website,d=com
    a=list(a)
    c=list(c)
    d=list(d)

    print(a,c,d)
    alp="qwertyuiopasdfghjklzxcvbnm"
    g=list(alp)
    l=["_"]
    m=[1,2,3,4,5,6,7,8,9,0]
    m=list(map(str,m))
    print(g,l,m)
    for i in range(len(a)):
        if a[i] not in g or a[i] not in l or a[i] not in  m:
            print("invalid ")
            return
    for i in range(len(c)):
        if c[i] not in g or c[i] not in  m:
            print("invalid")
            return
    for i in range(len(d)): 
        if d[i] not in g or len(c)!=3:
            print("invalid")
            return
    print("valid")

n=input()
p(n)

it still gives the same output

Rahul
  • 11
  • 2

0 Answers0