Why you miss what you have : if you have it now, you are trying to check if the whole string is in addrs
(that is, if it is ".com" or ".es" ), when what you really want to do is check if those chains are contained within the string entered by the user.
How you can fix it : to search for substrings you can use find
, a function that detects if one string contains another, and that it will return the position of the first occurrence of the searched substring, or -1 if it was not found.
Then for what you want to do:
Create a variable that will indicate if the substring was found and initializes to false.
Create a loop that traverses the values of addrs
and check if they are in the string entered by the user
If they are, change the variable from point 1 to true
The code could be something like this ( and you can see it running here ):
addr = raw_input('Introduce la ip o el nombre de dominio: ')
addrs= [".com", ".es"]
encontrado = False
for valor in addrs :
if addr.find(valor) > -1 :
encontrado = True
if encontrado :
print "es un dominio"
else:
print "es una ip"
Although as indicated by Toledano in a comment , another option ( more effective, of course) would be to create a regular expression that detects if the string is an IP and act accordingly.