-1
I would like the variable of input() retain its type int were only converted to string when exclusively entered with’s' digit so that I can exit the loop, without changing the while, there is some function that evaluates or would treat the way I am wanting?
import string
lista = list(string.ascii_lowercase[:6])
while True:
for i,l in enumerate(lista, start=1):
print(f"{i}. {l}")
try:
vm = int(input("Qual item deseja ou 's' para sair: "))
if vm == 's':
break
except IndexError:
print("Tente um indice existente.")
break
except ValueError:
print("Entre com uma opção existente.")
break
Have you thought about seeing if it’s like
's'before making the conversion? If it is's'you do thebreak, otherwise make the conversion toint?– Daniel Mendes
In what way? Because I could change the while x != ’s', but I intend to know another way.
– Allan Belem
@Allanbelem The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero