This forum is now read-only. Please use our new forums at discuss.codecademy.com.

The NPR API Forum

View Course » View Exercise

548 points
52ec4548548c35e32d000273_29857930
Submitted by
Jeff Koller
over 4 years ago

What is wrong with my 'if' statement?

I pass with this code, however the interpreter prints "You must enter an NPR ID, a search term, or both." whether I enter and NPR ID, search string, or both. Can anyone help me with my if statement?

npr_id = raw_input("Enter comma-seperated NPR IDs or leave blank.")
search_string = raw_input("Enter your search string or leave blank.")
feed_title = raw_input("What's your feed title?")

if npr_id == True or search_string == True:
    raw_input("Hit Enter to download your podcast.")
else:
    print "You must enter an NPR ID, a search term, or both."

1 vote

permalink

if npr_id == True or search_string == True:

You can not not check the value with True/False. For int and stings it will always return False.

Try:
if npr_id != "" or.....

591 points
53a645d49c4e9dfa07003689_657204180
Submitted by
Leo Hart
almost 4 years ago


0 votes

permalink

i dont see anything wrong it kept giving me syntax errors with that line and now im stuck at the next point. I've checked around and i see nothing wrong with you line, but i did find out that

if npr_id or search_string:

works just as good as your code, and is a bit less code
if i find anything else out ill try to help out.

681 points
Bc1de328926d2db0f6fdcbccd8760780?s=140&d=retro
Submitted by
Alex Babuca
over 4 years ago


0 votes

permalink

from urllib2 import urlopen
from urllib import quote

key = "APIKEY"
url = 'http://api.npr.org/query?apiKey=' + key
url += '&numResults=3&action=Or&requiredAssets=audio&format=Podcast'

nprid = rawinput("Enter comma-seperated NPR IDs or leave blank.")
searchstring = rawinput("Enter your search string or leave blank.")
feedtitle = rawinput("What's your feed title?")

if nprid or searchstring == True:
raw_input("Hit Enter to download your podcast.")
else:
print "You must enter an NPR ID, a search term, or both."

1730 points
51f64cd39c4e9d8afe00cf29_465129137
Submitted by
InomNorkul_519ca6f2c451a1b161002459_
over 3 years ago