In: Computer Science
Write a python program that asks the user about their emails and then check the following:
| Sample run | Sample run | Sample run |
|---|---|---|
| write your email address: [email protected] The email address is Valid The entered email is a KFUPM email The entered email is a freshman student email |
write your email address: ics@104. The entered email is not valid |
write your email address: [email protected] The email address is Valid |
Python program :
#asking user to enter email
email=input("write your email address:")
#checking if email contains @
if(email.find("@")!=-1 and email.find(".")!=-1):
#if email is valid
#checking if email contains some domain name
emailList=email.split(".") #split email based on .
if(len(emailList)>1 and emailList[1]!=''):#when length of emailList is greater than 2
#means email contains domain name
print("The email address is Valid")
#checking for KFUPM
if(emailList[0].split("@")[1].upper()=="KFUPM"):
#when email is KFUPM email
print("The entered email is a KFUPM email")
#checking for whether freshman email
userName=emailList[0].split("@")[0]
if userName.startswith('s')==True:
#when email id starts with s then checking for length of email
#spliting into characters
idList=list(emailList[0].split("@")[0])
#declaring variable for digitCount
digitCount=0
#using for loop
for i in range(1,len(idList)):
if(idList[i].isdigit()):
#when idList is digit then
digitCount=digitCount+1 #increment digit count
if digitCount==9: #when digitCoutn is 9 then
print("The entered email is a freshman student email")
else:#when email does not contains KFUPM
print("The entered email is a valid email")
else:#when email contains . but not contains domain name
print(email + " is not valid")
else: #if email does not contains @
print(email+" is not valid")
******************************************************
Screen for indentation :


===================================================
Screen when email is freshman email :

Screen when email is not valid :

Screen when email is KFUPM email :
