Your code has two important considerations that were not addressed satisfactorily in the other answers.
1) Redundancy in function input
. If you read the official documentation of the function, you will see the following passage (adapted):
The Function then reads a line from input, converts it to a string (stripping a trailing newline), and Returns that.
That is, the return of the function will always be a string, regardless of the content read. Thus, do str(input(...))
is to insert redundancy into the code and make one¹ more unnecessary call.
2) Responsive to the text box. The comparison you made was 'Enzo' in nome.lower()
and it will never be valid, because you are basically seeking a string with uppercase characters in a string which is certainly composed only of small characters, since it used the method lower()
. It would be the same as fetching the number 7 in a set of even numbers. The logic is right, but failed to implement.
That said, your code would basically be:
nome = input('Qual é o seu nome completo?')
print('Seu nome tem Enzo? {}'.format('Enzo' in nome))
See working on Repl.it | Ideone | Github GIST
However, this would produce an output such as:
Seu nome tem Enzo? True
Seu nome tem Enzo? False
It’s strange to have True
or False
in the midst of a string in English. At least I think. It would make more sense for me to appear "yes" or "no", and for that, it would be enough to do:
nome = input('Qual é o seu nome completo?')
tem_enzo = 'Sim' if 'Enzo' in nome else 'Não'
print(f'Seu nome tem Enzo? {tem_enzo}')
See working on Repl.it | Ideone | Github GIST
To make the check that is not sensitive to the box, just use the method lower
, but taking care to look for a string composed only of lowercase characters, such as in:
'enzo' in nome.lower()
Note: it is worth remembering that this method may not be entirely efficient, since it would return as true if the user’s name was Lorenzo, because it has 'enzo'
in the name. If it is interesting to check only by the full term, the solution would be another.
¹ It is not just a call, since str
is a native Python class, not a function. What happens in this case is the constructor call.
Seems to be the case mark an answer as accepted. Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.
– Barbetta