The problem is that the Python language differentiates upper case letters from lower case letters, so the string "Denise"
is different from "denise"
and surely you are writing the other names with capital letters as for example: "Maria"
, "Joao"
, "Pedro"
.
To fix the problem, just make the string returned from input()
lower case using the string method lower()
, thus:
nome = input("Qual o seu nome?").lower() # Transforma em minúsculo
if nome == 'denise':
print("Nome bonito")
elif nome == 'maria' or nome == 'pedro' or nome == 'joao':
print("Nome popular no brasil")
else:
print("Seu nome é bem normal")
Another important detail to add is that Python not only differentiates upper-case letters from lower-case letters, but also differentiates letters with accented letters without accents.
So the string "joão"
(with accent in A) is different from "joao"
(without accent in A).
And here’s a hint bonus to close the reply:
The function input()
always (unless overwritten) will return a string even if the user input is numeric. So, use the str()
in this case is redundant and will increase your code unnecessarily :)
So, I did what you said and it still doesn’t work: I reduced the code and wrote just that. name= str(input("Type your name")) if name ="Denise": print("Nice name") and even if I just type this the python doesn’t print, just ask "type your name" however if I change and put the number 1 in place of Denise it prints. Can you tell me why?
– Denise Prinsloo
No you did not do what I said in the reply. Now you check if the name is
"Denise"
(capital letters), but if you write"denise"
Tiny isn’t gonna work. How about copying the answer code into a separate file, testing the code and studying it to understand where you are missing ?– JeanExtreme002