程序无法正常工作

所以我没有收到任何错误,但它没有正确运行。用# **突出显示的代码位是错误的地方。因此,当我运行它时,无论是否放入.com或.co.uk或.org.uk,它总是会打印出我的代码无效。程序无法正常工作

import time 

#Imports the time library.

#3

#Email validator

#Make a program to check whether an email address is valid or not.

#You could make sure that there are no spaces, that there is an @ symbol and a dot somewhere after it. Also check that the end parts of the address are not blank.

#Extensions:

#1. When an email address is found to be invalid, tell the user exactly what they did wrong with their email address rather than just saying it is invalid

#2. Allow the user to choose to give a text file with a list of email addresses and have it process them all automatically.

print("Only .com or .co.uk or .org.uk are accepted.")

def ev():

#starts the definition and defines the command.

time.sleep(1)

#1 second wait

email = input("Email: ")

dot = "."

at = "@"

space = " "

com = ".com"

couk = ".co.uk"

org = ".org.uk"

if at not in email:

print("Invalid. There is no @ in your email.")

#Says email is invalid as there is no @

ev()

elif dot not in email:

print("Invalid. There is no .(dot) in your email.")

#Says email is invalid as there is no .

ev()

#Loops to asking for the email again

elif space in email:

print("Invalid. There shouldn't be any spaces in your email.")

#Says email is invalid as there is a space

ev()

#Loops to asking for the email again

elif com not in email or couk not in email or org not in email: # **

print("This email is not valid. Only .com or .co.uk or .org.uk are accepted.")**

ev()

#Loops to asking for the email again

else:

print("Valid!")

ev()

#Ends the definition so it starts automatically.

回答:

你需要and,而不是or

试试这个:

elif com not in email and couk not in email and org not in email: 

print("This email is not valid. Only .com or .co.uk or .org.uk are accepted.")**

ev()

#Loops to asking for the email again

以上是 程序无法正常工作 的全部内容, 来源链接: utcz.com/qa/257105.html

回到顶部