I'm starting in Python and programming in general and now that I had a few notes in hand, I started writing a simple program that consists of a menu with different options.
The first consists simply of a loop that allows you to enter ages in a list.
The problem I have is that after asking for confirmation in the loop to exit the break
it does not cause the condition to be false
and end the loop. I have tried with return False
and the result is the same, I do not finish the loop to invoke the function menu()
and return to the beginning.
while True: # bucle para introducir edades en la lista
valor = input("Introduce edad: ") # pedir valor por teclado
listaedad.append(valor) # añadir valor a listaedad
confirm = input('Quieres seguir? ') # confirmación para seguir con el bucle
if confirm in ('s', 'si', 'Si', 'SI'): # si confirm es igual a los valores del IN
continue # continua en el while
elif confirm in ('n', 'no', 'No', 'NO'): # si confirm es igual a los valores de IN
print("Saliendo...") # imprime mensaje de salida
break # sal del bucle
else: # si confirm es cualquier otro valor distinto de SI/NO
print('Opción no reconocida') # imprime mensaje
print('Saliendo...') # imprime mensaje
break # sal del bucle
return listaedad #retorna la lista
menu() # vuelve al menu de inicio