How to use the strip () function next to a list or tuple in python?

1

I am creating a script and in a snippet I create a list and then I use the strip () function next to upper () inside input v1, but at the time of calling the script and executing it it returns nothing, how can I to solve this?

....
    opcao_sim = ('SIM','YES')
    opcao_nao = ('NÃO','NO')
    v1 = str(input('Deseja criar um repositorio? n[s]: ')).strip().upper()[0]
    if v1 in op_sim:
            print('ok! bons estudos XD')
            sys.exit(0)
    ...
    
asked by anonymous 31.03.2018 / 04:33

2 answers

0

Your code is validating with op_sim , but I believe it is opcao_sim .

Regardless of this you are getting the first character of the answer ("S", "Y" etc) and looking for it within the ("SIM", "YES") tuple. The simplest solution is to replace the tuple with a string , something like opcao_sim="SY" and then the validation will work correctly.

Tip, it's best to use v1=str(input("...")).strip()[0].upper() if you only need the first character of the response.

    
31.03.2018 / 05:52
0

I understood my own error, in case someone is with that same doubt.

  sim = ('S','Y')
    nao = ('N')
    v1 = str(input('Digite sim ou não ')).strip()[0].upper()
    if v1 in sim:
            print('você digitou sim ')
    elif v1 in nao:
            print('Você digitou não ')

In the list you have to put the letter that you want to take, it was a very silly mistake .. and if you use the .upper () place the letter in upper case or if it is .lower

remembering that [0] means that you want the first letter, since python starts counting from 0

    
31.03.2018 / 16:08