Editing Community Data Science Course (Spring 2023)/Week 4 coding challenges
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
There's actually nothing to download this time | There's actually nothing to download this time. After class, we'll update with a link to a notebook that is a cleaned up version of what we walked through during the lecture though since this code will likely be very useful. | ||
== #1 Bored API == | == #1 Bored API == | ||
First, let's work through a few examples from the [http://www.boredapi.com/ Bored API]. In order to answer these, you'll need access to the API activity endpoint (https://www.boredapi.com/api/activity) and the documentation at http://www.boredapi.com/. My strong advice is to start building your work off the code I did in class which is in the [https://github.com/kayleachampion/spr23_CDSW/blob/main/curriculum/week4/week4_lecture_part_1_bored_api.ipynb week 4 lecture part 1Jupyter notebook]. | First, let's work through a few examples from the [http://www.boredapi.com/ Bored API]. In order to answer these, you'll need access to the API activity endpoint (https://www.boredapi.com/api/activity) and the documentation at http://www.boredapi.com/. My strong advice is to start building your work off the code I did in class which is in the [https://github.com/kayleachampion/spr23_CDSW/blob/main/curriculum/week4/week4_lecture_part_1_bored_api.ipynb week 4 lecture part 1Jupyter notebook]. | ||
# Write some Python code to use the API to get | # Write some Python code to use the API to get a free activity that I could do with my partner. Turn the data from the API into a sentence that tells me the activity, its accessibility, and its price. | ||
## Extend that code so that it gets me 5 activities and have it write a nicely formatted output. | ## Extend that code so that it gets me 5 activities and have it write a nicely formatted output. | ||
# First, get a totally random activity from the API. Print it out, along with its activity type. Now get me another activity that's of the same type as the first random activity. Print it out too, plus its activity type (to check that they're the same). | # First, get a totally random activity from the API. Print it out, along with its activity type. Now get me another activity that's of the same type as the first random activity. Print it out too, plus its activity type (to check that they're the same). | ||
Line 24: | Line 17: | ||
# Write a URL that will return 5 dog facts at once (just the link is fine) | # Write a URL that will return 5 dog facts at once (just the link is fine) | ||
# Take your URL to request a single dog fact and put into a Python program that uses <code>requests.get()</code> and passes in parameters with the <code>params=</code> argument. Your program should just print out the fact itself and not the full JSON object | # Take your URL to request a single dog fact and put into a Python program that uses <code>requests.get()</code> and passes in parameters with the <code>params=</code> argument. Your program should just print out the fact itself and not the full JSON object | ||
# Finally, write a for loop that gets sets of | # Finally, write a for loop that gets 5 sets of facts 5 times (you can just try something like <code>for number in [1,2,3,4,5]</code>, downloads the lists of dog facts, and then writes out a new tab-separated values (TSV) file with columns: (1) ID of the dog fact, and (2) the fact itself! | ||
== #3 Mapping! == | == #3 Mapping! == |