This forum is now read-only. Please use our new forums! Go to forums
Enter your zip code: duplication?
Enter your zip code: appears twice, with the first having no effect(e.g. doesn’t matter if its empty or not)
The code does run and etc.
from urllib2 import urlopen
from json import load
key = "API_KEY"
url = 'http://api.npr.org/stations?apiKey=' + key + '&format=json'
zip_code = raw_input("Enter your zip code: ")
url += '&zip=' + zip_code
def call_station_api(url):
response = urlopen(url)
j = load(response)
return j
def parse_station_json(json_obj):
for station in json_obj['station']:
print station['callLetters']['$text']
print station['marketCity']['$text']
print station['state']['$text']
url = build_api_call(key)
print "URL: " + url
json_obj = call_station_api(url)
parse_station_json(json_obj)
Answer 537d9646282ae3ff91000eb5
0 votes
you have to print each item in one print statement
print station['callLetters']['$text']+": "+\
station['marketCity']['$text']+", "+\
station['state']['$text']
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency