Created
December 9, 2016 15:52
-
-
Save JeffCohen/c8693203198cc94b64a3db36e736d622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 | |
# | |
# https://docs.python.org/3/howto/urllib2.html | |
# http://api.open-notify.org/astros.json | |
# This code works. Run it to verify. | |
# Then read the challenge at the bottom of this file. | |
import urllib.request | |
import json | |
url = "http://api.open-notify.org/astros.json" | |
def whos_in_space(): | |
data = retrieve_space_data() | |
for person in data['people']: | |
print(person['name']) | |
def retrieve_space_data(): | |
with urllib.request.urlopen(url) as response: | |
json_data = response.read().decode('utf8') | |
return json.loads(json_data) | |
whos_in_space() | |
# Challenge: Can you display the names in alphabetical order? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment