It would be something like:
if menu() == "Sim":
#chama o menu
else:
#fecha o programa ou outra
Yet that would not be case-sensitve, then you can use .lower()
, because if it is YES, yes, yes, Sim, yes, Sim and etc will work, example:
def menu():
ver = input('Você deseja ver o nosso menu?[Sim/Não]')
return ver.lower()
if menu() == "sim":
print("Escreveu sim")
else:
print("Escreveu qualquer outra coisa")
To facilitate you can also use only S and N (the N is relative, actually anything other than S and SIM would be no), for this use the in
:
def menu():
ver = input('Você deseja ver o nosso menu? Para confirmar digite Sim ou S ou Yes ou Y: ')
return ver.lower()
if menu() in [ "sim", "s", "yes", "y" ]:
print("Escreveu sim")
else:
print("Escreveu qualquer outra coisa")
If the input
is used for other "commands" you will create just using the elif
(python has no switch/case structure) and save the value of input()
in a variable, so for example:
def meuApp():
resposta = input('Digite o seu comando: ').lower()
if resposta == "menu":
print(
"""1 - Digite "menu" (sem aspas) para abrir o menu novamente\n"""
"""2 - Digite "produtos" (sem aspas) para ver os produtos\n"""
"""3 - Digite "fechar" (sem aspas) para encerrar o programa\n"""
)
elif resposta == "produtos":
print("\n\n\nExibindo os produtos\n\n\n")
elif resposta == "fechar":
exit()
else:
print("Invalido")
meuApp() # deixa o app recursivo
meuApp() #inicia
You are already returning.
– Maniero
I reversed the issue because the new code doesn’t make much sense and misrepresents the answer, could it explain better what you don’t understand yet? Apparently the use of IF you have already understood, or not?
– Guilherme Nascimento
First I did the editing and then I went to explain. I’m trying to make a loop , but the input is what’s not being recognized and I think that’s why the loop doesn’t end. The problem is how to make this input that is inside the function be recognized. Only for this new code: def ver(): veja = input('Do you want to see our menu?[Yes/No]') while True: ver() if veja == 'Yes'. Lower(): break
– Lucas Souza
I still don’t know how to add the code the right way in the comment.
– Lucas Souza
IF has to go inside While, indented ... but I don’t understand why you put While, do as I did in the last example, use "recursion" in your
def
.– Guilherme Nascimento
The
ver()
be set inveja
, it should be like this... True: veja = ver() if veja == ...
– Guilherme Nascimento
I used the last example and it worked, but I could not make the loop until the user type yes
– Lucas Souza
Could explain better what you want, can’t understand what use you want with this loop
– Guilherme Nascimento
@Guilhermenascimento I want to loop this question from the menu until you type yes
– Lucas Souza