Your code has two important considerations that were not satisfactorily addressed in the other answers.
1) Redundancy in function input
. If you read the official function documentation , you will see the following excerpt:
The function then reads a line from input, converts it to string (stripping a trailing newline), and returns that.
That is, the function return will always be a string , regardless of the content read. So, str(input(...))
is to insert redundancy into the code and make one ¹ too unnecessary call.
2) Sensitive to the text box. The comparison you made was 'Enzo' in nome.lower()
and it will never be valid, since you are basically looking for a string with uppercase characters in a string only by lowercase, since you used the lower()
method. It would be the same as searching for the number 7 in a set of even numbers. Logic is right, but implementation failed.
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 at Repl.it | Ideone | GitHub GIST
However, this would produce output such as:
Seu nome tem Enzo? True
Seu nome tem Enzo? False
It's strange to have True
or False
in the middle of a string in Portuguese. 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 at Repl.it | Ideone | GitHub GIST
To make the check that is not case-sensitive, you only need to use the lower
method, but be careful to search for a string composed only of lowercase characters, such as
'enzo' in nome.lower()
Note: Note that this method may not be fully efficient, since it would return as true if the user name was Lorenzo, since it has 'enzo'
in the name. If it is interest to check only for 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 call of the constructor.