0

I'm developing a chatbot project for college, and in the following code block, the first if is always going as a true value, no matter what. I really need help and don't know what to do, cause this project is due on monday.

def registeredClient():
 print('Olá, bem-vindo a WE-RJ Telecom!')
 userInputString = str(input('O que você precisa?\nCaso queira contratar ou trocar de plano escreva "Quero contratar" ou "Quero trocar de plano".\nCaso esteja com problemas de conexão, escreva "suporte".\nCaso queira seu boleto, digite "boleto":\n'))
 userInputString = userInputString.lower()
 if 'contratar' or 'trocar plano' or 'aumentar velocidade' or 'mudar plano' or 'velocidade' or 'plano' in userInputString:
 newPlanOption()
 elif 'suporte' or 'lenta' or 'internet lenta' or 'internet esta lenta' or 'problema' or 'velocidade' in userInputString:
 supportOption()
 elif 'boleto' or 'segunda via' or '2a via' or 'fatura' in userInputString:
 billingOption()
 else:
 print('Não foi posível entender a sua mensagem, seu atendimento será encerrado.')
 return False
Arkistarvh Kltzuonstev
6,9687 gold badges32 silver badges62 bronze badges
asked Nov 20, 2022 at 4:53
2

2 Answers 2

1

I updated the conditions. In your case your conditions were checking if the strings themselves were truthly which is why your first case would result in true.

def registeredClient():
 print('Olá, bem-vindo a WE-RJ Telecom!')
 userInputString = str(input('O que você precisa?\nCaso queira contratar ou trocar de plano escreva "Quero contratar" ou "Quero trocar de plano".\nCaso esteja com problemas de conexão, escreva "suporte".\nCaso queira seu boleto, digite "boleto":\n'))
 userInputString = userInputString.lower()
 if any(x in userInputString for x in ['contratar', 'trocar plano' , 'aumentar velocidade' , 'mudar plano' , 'velocidade' , 'plano']):
 print("Case A")
 elif any(x in userInputString for x in ['suporte', 'lenta' , 'internet lenta' , 'internet esta lenta' , 'problema' , 'velocidade']):
 print("Case B")
 elif any(x in userInputString for x in ['boleto' , 'segunda via' , '2a via' , 'fatura']):
 print("Case C")
 else:
 print('Não foi posível entender a sua mensagem, seu atendimento será encerrado.')
 return False
 
registeredClient();

answered Nov 20, 2022 at 5:01
Sign up to request clarification or add additional context in comments.

Comments

0

The first if block is understood by python as the following if block :

(if 'contratar') or ('trocar plano') or ('aumentar velocidade') or ('mudar plano') or ('velocidade') or ('plano' in userInputString): 

which is always True as the strings are not vacant and thus truthy type.

What you need is this as the first if block :

if any(i in userInputString for i in ['contratar', 'trocar plano', 'aumentar velocidade', 'mudar plano', 'velocidade', 'plano']):

Similarly you need to change your elif statements too.

Try this :

def registeredClient():
 print('Olá, bem-vindo a WE-RJ Telecom!')
 userInputString = str(input('O que você precisa?\nCaso queira contratar ou trocar de plano escreva "Quero contratar" ou "Quero trocar de plano".\nCaso esteja com problemas de conexão, escreva "suporte".\nCaso queira seu boleto, digite "boleto":\n'))
 userInputString = userInputString.lower()
 checkString = lambda l: any(i in userInputString for i in l)
 if checkString(['contratar', 'trocar plano', 'aumentar velocidade', 'mudar plano', 'velocidade', 'plano']):
 newPlanOption()
 elif checkString(['suporte', 'lenta', 'internet lenta', 'internet esta lenta', 'problema', 'velocidade']):
 supportOption()
 elif checkString(['boleto', 'segunda via', '2a via', 'fatura']):
 billingOption()
 else:
 print('Não foi posível entender a sua mensagem, seu atendimento será encerrado.')
 return False
answered Nov 20, 2022 at 4:59

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.