Python error with elif conditionals not taken into account

0

The error is that when I execute my code with the conditional if it executes it well but when I try the elif it does not take it into account and goes directly to the if for some reason. Here the code:

nombre_usuario=str(input("como debo de llamarte usuario?... "))

verificacion=str(input("excelente, vuestro nombre es "+str(nombre_usuario)+" 

correcto??? responde de manera afirmativa para si, negativa para no "))

if verificacion=="si "or"SI"or"Si"or"S"or"s":

    print("afirmativo verificacion confirmada "+str(nombre_usuario))

elif verificacion=="no"or"NO"or"No"or"N"or"n":

    print("afirmativo nombre no valido...reiniciando protocolo_inicio")
    
asked by gean cristofano 10.10.2018 в 18:06
source

1 answer

2

Another alternative where you make it simpler and do not have to put as many ' or ' in the if sentence would be using a list (< em> list ) with the different responses that the user can give:

nombre_usuario = str(input("como debo de llamarte usuario?... "))

verificacion = str(input("excelente, vuestro nombre es "+str(nombre_usuario)+"correcto??? responde de manera afirmativa para si, negativa para no "))

palabras_no = ['no', 'No', 'n', 'NO', 'oN']
palabras_si = ['si', 'SI', 'Si', 'S', 'sI']

if verificacion in palabras_no:
    print('Hago lo que sea no.')

if verificacion in palabras_si:
    print('Hago lo que sea si.')

And to avoid having to have so many options you can always pass what the 'user' writes to lowercase with the function lower () which is a practice that is usually done.

username = str (input ("how should I call you user? ..."))

verificacion = str(input("excelente, vuestro nombre es "+str(nombre_usuario)+"correcto??? responde de manera afirmativa para si, negativa para no "))

palabras_no = ['no', 'n']
palabras_si = ['si', 's']

if verificacion.lower() in palabras_no:
    print('Hago lo que sea no.')

if verificacion.lower() in palabras_si:
    print('Hago lo que sea si.')
    
answered by 10.10.2018 в 19:27