Click here to Skip to main content
15,881,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to write shorter condition than this

Python
y = (website[-4:]!=".com" and website[-4:]!=".net" and website[-4:]!=".org"
    and website[-4:]!=".gov" and website[-4:]!=".edu")


What I have tried:

Python
website = str(input("Enter your URL: "))
protocol = "http://www."
site = [".com" , ".net" , ".org" , ".gov" , ".edu"]

y = (website[-4:]!=".com" and website[-4:]!=".net" and website[-4:]!=".org"
 and website[-4:]!=".gov" and website[-4:]!=".edu")

# how to replace y with shorter condition

if website[0:11] != protocol:
    print("invaild")
elif website[0:11] == protocol:
    for i in site:       
        if website[-4:]==i:  
            print("http")
            print("www")
            print(website[11:-4])
            print(website[-3:])
        elif y == True:
            print("invaild")    
            break
Posted
Updated 13-Dec-22 20:32pm
v2

1 solution

Quote:
I want to write shorter condition than this

Python
y = (website[-4:]!=".com" and website[-4:]!=".net" and website[-4:]!=".org"
and website[-4:]!=".gov" and website[-4:]!=".edu")

Python
y =  not (website[-4:] in site)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900