0

Ok, so my problem is that basically I'm learning how to use APIs and there's this problem keeping me behind. The problem is that although I keep putting the new string for it to recognize it and start my elif, it keeps giving me the result as if I assigned my variable with the first string. Here's the code, hope you can help me with this.

import requests
import json

print('Welcome to the quote app')

nombre = input('Whats your name? : ')
opcion = ''

print('\n See all of our options\n')
print('Random Quote')
print('Quote Of the Day')

opcion = input('Select an option: ')

respuesta = opcion.lower()
del(opcion)

if respuesta == 'random quote' or 'randomquote' or 'random quote ':

#The  GET for this answer is inside here

elif respuesta == 'quote of the day ' or 'quoteoftheday' or 'quote of the day ':

#The GET for this answer is inside here


#Terminal answer

Welcome to the quote app
Whats your name? : milton

 See all of our options

Random Quote
Quote Of the Day
Select an option: quote of the day
milton ,Your random quote of the day is:  Your fears, your critics, your heroes, your villains: They are fictions you perceive as reality. Choose to see through them. Choose to let them go.
Said by:  Isaac Lidsky
rioV8
  • 24,506
  • 3
  • 32
  • 49
  • 3
    Does this answer your question? [Why does \`a == x or y or z\` always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true) – mangupt May 01 '21 at 06:27
  • 1
    You should have extracted a [mcve] from your code. It would have told you that JSON, API, VS Code and `python-requests` are completely irrelevant. Also, above code isn't valid Python, so people here can't even try it out. Overall, it's not a helpful question. As a new user, please take the [tour] and read [ask]. – Ulrich Eckhardt May 01 '21 at 06:52

2 Answers2

0

Your if and elif statements are wrong, you should do:

if respuesta == 'random quote' or respuesta == 'randomquote' or respuesta == 'random quote ':
#The  GET for this answer is inside here


elif respuesta == 'quote of the day ' or  respuesta == 'quoteoftheday' or respuesta == 'quote of the day ':
#The GET for this answer is inside here

You can also improve it by doing:

if respuesta in ['random quote', 'randomquote', 'random quote ']:
#The  GET for this answer is inside here
elif respuesta in ['quote of the day', 'quoteoftheday', 'quote of the day ']:
#The  GET for this answer is inside here

Online example

0

Correct if and elif statements:

if respuesta in ('random quote', 'randomquote', 'random quote '):
    #The  GET for this answer is inside here
elif respuesta in ('quote of the day ', 'quoteoftheday', 'quote of the day '):
    #The GET for this answer is inside here
mangupt
  • 369
  • 2
  • 11