diff --git a/Exercise-2.ipynb b/Exercise-2.ipynb index 311bd53..5ba9a37 100644 --- a/Exercise-2.ipynb +++ b/Exercise-2.ipynb @@ -1,802 +1,822 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "ae31a79f785ace6d84d46d473093a0d7", - "grade": false, - "grade_id": "cell-577a4204893ab1a5", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "# Exercise 2 - Lists and indices\n", - "\n", - "The exercise for this week is meant to help you better understand data types and lists in Python, and practice saving changes to your files using Git and GitHub. \n", - "\n", - "Exercise 2 consists of 3 problems that you can find in this notebook. For each problem you need to modify the notebook either by fixing problems in existing code, or by adding your own solutions. Remember to push your changes to GitHub already while working, not only at the very end!\n", - "\n", - "- **Exercise 2 is due by 09:00 on 18.9.**\n", - "- Scores on this exercise are out of **20 points**.\n", - "\n", - "## Please note\n", - "\n", - "- **Some of the cells in this Jupyter Notebook are \"Read-only\" which means that you are not able to edit them.**\n", - "\n", - "- **Some of the code cells contain tests. If these tests fail, you know there is still something wrong with your code.**\n", - "\n", - "- **Some of the code cells raise** `NotImplementedError`. **This error tells you that you need to somehow modify that code cell.**\n", - "\n", - "\n", - "## Where to find help\n", - "\n", - "If you're having trouble, please remember you can\n", - "\n", - "- Come to the work sessions on Thursday and/or Friday for help from the course assistants\n", - "- Check out [the hints for this week's exercise](https://geo-python.github.io/site/lessons/L2/exercise-2.html) on the course webpage\n", - "- Post questions to Slack" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "0945eeb4936351eaf0d94e7eeda681b9", - "grade": false, - "grade_id": "cell-51a3fbb6b8d35c74", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "## Problem 0 - Cloning Exercise repository to JupyterLab (*0 points*)\n", - "\n", - "Before starting to work with the actual problems for this week, you should start a new JupyterLab instance and clone **your own** Exercise 2 repository (e.g. `exercise-2-htenkanen`) into the instance using **Git** as we saw in the [lecture this week](https://geo-python.github.io/site/lessons/L2/git-basics.html). " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "1e48e671ada57c103606dcff081e2f67", - "grade": false, - "grade_id": "cell-34d197ef67f874ec", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "## Problem 1 - Making changes to code and using Git (*7 points*)\n", - "\n", - "Your first task for this week is to make some modifications to the Python code in the cells below to fix the errors it gives once you run the code cells.\n", - "The code should allow users to find the operational time of an [FMI observation station](http://en.ilmatieteenlaitos.fi/observation-stations) by setting the `selected_station` variable.\n", - "*Don't worry about the case of a station name that is not on the list.*\n", - "\n", - "**The main aim is to print out an informative sentence that tells how long the selected station has been operational, for example** \n", - "\n", - "```\n", - "'The Helsinki Harmaja station has been operational for 30 years.'\n", - "```\n", - "or\n", - "```\n", - "'The Helsinki Kaivopuisto station has been operational for 115 years.'\n", - "```\n", - "\n", - "However, if you try to run all the code cells under Problem 1, you will run into errors. Your task is to find **3 things to fix** in the code cells under Problem 1. Once you succeed, the final print statement should work, and you should be able to modify the output only by setting a different station name.\n", - "\n", - "\n", - "### Grading for Problem 1\n", - "\n", - "Your score for this problem will be based on\n", - "\n", - "- Fixing **3 problems in the code** to get the code working as expected\n", - "- Committing each change separately to GitHub using Git\n", - "- Listing the changes you needed to make to get the code working in plain English by modifying the existing text or adding a Markdown cell above each change" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "ab9c79af966da5fb76c4ad608b1092ea", - "grade": false, - "grade_id": "cell-624ad911a29570ae", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "Here we create and fill lists of station names and starting years for observation.\n", - "**NOTE**: Long lines can be split into multiple lines using the \"\\\\\" character.\n", - "\n", - "*These code cells are \"Read-only\" - you won't be able to modify the input lists, but you still need to run them.*" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "4ac3f062a25698525019129839ce9911", - "grade": false, - "grade_id": "cell-f16d9e1598382abb", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "# Read-only code cell\n", - "station_names = ['Harmaja', 'Kaisaniemi', 'Kaivopuisto', 'Kumpula', 'lighthouse', \\\n", - " 'Malmi airfield', 'Suomenlinna aaltopoiju', 'Vuosaari harbour']" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "f032518a728ed6265d49f81a297405d8", - "grade": false, - "grade_id": "cell-a6fa30a83026c13c", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "# Read-only code cell\n", - "station_start_years = [1989, 1844, 1904, 2005, 2003, 1937, 2016, 2012]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "761974bf8be2a6cff3e58447802c0021", - "grade": false, - "grade_id": "cell-111a923765d7da38", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "Below we can define the selected station:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "9254c6a4adf5b0423f1d442947675b10", - "grade": false, - "grade_id": "selected_station", - "locked": false, - "schema_version": 3, - "solution": true - } - }, - "outputs": [], - "source": [ - "# YOUR CODE HERE\n", - "raise NotImplementedError()\n", - "\n", - "selected_station = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "241fe542d1b14c123a540aa9c0e5d577", - "grade": true, - "grade_id": "selected_station_test", - "locked": true, - "points": 1, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "print(selected_station)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "acb6b2147cd39c8522eaa4b39e396483", - "grade": false, - "grade_id": "cell-8c0ab6cf80173158", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "Next we find the location of the selected station in the list of station names:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "09ba7c08752ddb3b990b9ac08069706a", - "grade": false, - "grade_id": "cell-4d559812a8644360", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "# Read-only code cell\n", - "station_index = station_names.index(selected_station)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "eafd36633edc38a9b0494d58e3cdad41", - "grade": false, - "grade_id": "cell-5b6020cf2c5808a6", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "Now we can calculate the years the station has been operational:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "bcf3de34954938e8522f5e27960b6efd", - "grade": false, - "grade_id": "station_years", - "locked": false, - "schema_version": 3, - "solution": true - } - }, - "outputs": [], - "source": [ - "# YOUR CODE HERE\n", - "raise NotImplementedError()\n", - "\n", - "station_years = 2019 - station_start_years[selected_station]" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "6e6842fd2b3547fda0eda04d242eeebc", - "grade": false, - "grade_id": "cell-a3782621daec92f2", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "\n", - "Now, we can print the station name and number of years of operation to the screen.\n", - "A sample print statement on screen is `'The Helsinki Harmaja station has been operational for 30 years.'` The print statements should work for all listed stations only by modifying the `selected_station` -variable that is defined earlier in this problem." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "57c63db7d9a30090b281f69b7c8bb344", - "grade": false, - "grade_id": "print_statement", - "locked": false, - "schema_version": 3, - "solution": true - } - }, - "outputs": [], - "source": [ - "# YOUR CODE HERE\n", - "raise NotImplementedError()\n", - "\n", - "print_statement = \"The Helsinki \" + selected_station + \" station has been operational for \"+ \\\n", - " str(station_years)+ \" years.\n", - "\n", - "print(print_statement)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "608ef6eb22a40eb0008db66f1b5ce0b3", - "grade": false, - "grade_id": "cell-f26de00add515a66", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "source": [ - "#### Tests for problem 1\n", - "\n", - "Finally, we can run some tests to see if things are working as they should! These tests may help you in solving the problem. Note, we also run some hidden tests for checking the exercises. If these tests pass, it's not a quarantee of a 100 % correct answer!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "c1476f92e71ae1258662e56cac344f49", - "grade": true, - "grade_id": "station_years_test", - "locked": true, - "points": 1, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "outputs": [], - "source": [ - "# importing tools for running some tests\n", - "from nose.tools import ok_, assert_equal\n", - "\n", - "#Validate that station_years is a variable of integer type\n", - "assert_equal(type(station_years),int)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "87f94557c7bd2562bcbb461d7e11c9ab", - "grade": true, - "grade_id": "print_statement_test1", - "locked": true, - "points": 2, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "outputs": [], - "source": [ - "#Validate that the print statement is correct for Harmaja station:\n", - "# Note! Your print statement should work for all the stations!\n", - "assert_equal(print_statement, 'The Helsinki Harmaja station has been operational for 30 years.')\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "32fec0c1502a8011243a66d7373db890", - "grade": false, - "grade_id": "final_answer_question", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "#### Summarize what you did in problem 1 using markdown\n", - "\n", - "Describe the 3 code changes you made below in plain English (you can, for example, use bullet points here):" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "db6c917ce6aabe7be4930af01bcb4e79", - "grade": true, - "grade_id": "final_answer_question_test", - "locked": false, - "points": 3, - "schema_version": 3, - "solution": true - } - }, - "source": [ - "YOUR ANSWER HERE" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "74ac9031ca05899cd868c38c5bf85a54", - "grade": false, - "grade_id": "cell-f328c6e177c1d29c", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "## Problem 2 - Accessing monthly average temperatures (*9 points*)\n", - "\n", - "The table below presents [monthly average temperatures recorded at the Helsinki Malmi airport](https://www.timeanddate.com/weather/finland/helsinki/climate).\n", - "\n", - "| Month | Temperature [°C] |\n", - "| --------- | :--------------: |\n", - "| January | -3.5 |\n", - "| February | -4.5 |\n", - "| March | -1.0 |\n", - "| April | 4.0 |\n", - "| May | 10.0 |\n", - "| June | 15.0 |\n", - "| July | 18.0 |\n", - "| August | 16.0 |\n", - "| September | 11.5 |\n", - "| October | 6.0 |\n", - "| November | 2.0 |\n", - "| December | -1.5 |\n", - "\n", - "In the code cells below, write some Python code that allows users to select a month and have the monthly average temperature printed to the screen.\n", - "For example, your code should display the following for the month of March:\n", - "\n", - "```\n", - "The average temperature in Helsinki in March is -1.0\n", - "```\n", - "\n", - "### Grading for Problem 2\n", - "\n", - "Your score for this problem will be based on\n", - "\n", - "- Having your notebook display the monthly average temperature in a selected month, set by defining the variable `selected_month_index`.\n", - " - **NOTE**: We expect you to use the index value to select the month, not the name of the month (e.g., \"May\").\n", - "- Having it work for all 12 months in the year.\n", - "- Describe how your code works in a few sentences of plain English in the Markdown cell above your code\n", - "- Including inline comments to clearly explain how the code works between most and/or all lines of your code in its Python cell\n", - "- Pushing your script to your GitHub repository for this week's lesson." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "3da4af3cfd142ea4b7dbcebf08d9577a", - "grade": false, - "grade_id": "define_lists", - "locked": false, - "schema_version": 3, - "solution": true - } - }, - "outputs": [], - "source": [ - "# YOUR CODE HERE\n", - "raise NotImplementedError()\n", - "\n", - "# here is the variable which you use to set the selected month:\n", - "selected_month_index = None\n", - "\n", - "# Here are also the names of the two lists you should use for this problem. Please don't change the variable names!\n", - "months = None\n", - "average_temp = None\n", - "\n", - "# Using the lists and their indices, generate the desired print statement:\n", - "print_statement = None" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "9f4a92d1a4cb196f35ec5232048e8c96", - "grade": true, - "grade_id": "define_lists_test", - "locked": true, - "points": 2, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "# Check your print statement:\n", - "print(print_statement)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "00b0dad83f1549ec4727cc3500504aef", - "grade": false, - "grade_id": "cell-3fb0ac91413aeadc", - "locked": true, - "schema_version": 3, - "solution": false, - "task": false - } - }, - "source": [ - "#### Tests for problem 2\n", - "\n", - "Let's run some additional tests to see if things are working as they should! These tests may help you in solving the problem. Note, we also run some hidden tests for checking the exercises. If these tests pass, it's not a quarantee of a 100 % correct answer!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "ce013efc8079071c431b866b5c587da2", - "grade": true, - "grade_id": "list_length_test", - "locked": true, - "points": 2, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "#Validate the length of two lists are 12\n", - "ok_(len(months)==12)\n", - "ok_(len(average_temp)==12)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "f564a96fc2712c98dd682cc64a8e2c3c", - "grade": true, - "grade_id": "list_type_test", - "locked": true, - "points": 2, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "#Validate that variable months and average_temp are lists\n", - "ok_(isinstance(months, list), 'Variable months is not a list')\n", - "ok_(isinstance(average_temp, list), 'Variable average_temp is not a list')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "code", - "checksum": "bc1cdf5456733ed168588635b8d81960", - "grade": true, - "grade_id": "print_statement_test", - "locked": true, - "points": 3, - "schema_version": 3, - "solution": false - } - }, - "outputs": [], - "source": [ - "#Validate the print statement is correct; \n", - "# Set selected_month_index to correspond with July before running this cell.\n", - "# Note! Your code should work with any of the 12 months!\n", - "assert_equal(print_statement, 'The average temperature in Helsinki in July is 18.0')\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "editable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "9c032326d744df32ab2628ff703a9c36", - "grade": false, - "grade_id": "markdown_practice", - "locked": true, - "schema_version": 3, - "solution": false - } - }, - "source": [ - "## Problem 3 - More practice using Markdown (*4 points*)\n", - "\n", - "The last task in this week's exercise is to answer some questions and add an image in this notebook using Markdown. **Note**: You may want to read a bit more about [formatting text in Github-flavored Markdown](https://help.github.com/articles/basic-writing-and-formatting-syntax/).\n", - "\n", - "\n", - "### Grading for Problem 3\n", - "\n", - "Your score for this problem will be based on\n", - "\n", - "- Your answers to the three questions that are part of this problem\n", - "- Posting an image of a favorite animal using Markdown\n", - "\n", - "\n", - "#### 1. Give your responses to these three questions about this week's lesson:\n", - "\n", - " - What did you learn?\n", - " - What was unclear?\n", - " - What would you change?\n", - " \n", - " *Please use Markdown lists when answering these questions.*\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "bada3cbd3bcc24069b24f4db7e13dcd1", - "grade": true, - "grade_id": "answer_questions", - "locked": false, - "points": 2, - "schema_version": 3, - "solution": true - } - }, - "source": [ - "YOUR ANSWER HERE" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### 2. Adding an image\n", - "\n", - "Just for fun, add an image of an animal that you like along with a short caption giving its name and anything special you might like to add.\n", - "\n", - "You should add an image by linking to a website with the image, or if by uploading an image to your GitHub repository and linking to that (if you are looking for a challenge).\n", - "\n", - "We suggest that you search for images in a repository that includes licencing information such as [Wikimedia Commons](https://commons.wikimedia.org/wiki/Main_Page) or [Pixabay](https://pixabay.com/). You are, of course, also welcome to upload your own animal images. You can add it in a new Markdown cell under those used to answer the questions in part 1 of this problem." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "deletable": false, - "nbgrader": { - "cell_type": "markdown", - "checksum": "6bfc187e9555cb0dfa082b9960d1f1ff", - "grade": true, - "grade_id": "insert_image", - "locked": false, - "points": 2, - "schema_version": 3, - "solution": true - } - }, - "source": [ - "YOUR ANSWER HERE" - ] - } - ], - "metadata": { - "anaconda-cloud": {}, - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.4" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "ae31a79f785ace6d84d46d473093a0d7", + "grade": false, + "grade_id": "cell-577a4204893ab1a5", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "# Exercise 2 - Lists and indices\n", + "\n", + "The exercise for this week is meant to help you better understand data types and lists in Python, and practice saving changes to your files using Git and GitHub. \n", + "\n", + "Exercise 2 consists of 3 problems that you can find in this notebook. For each problem you need to modify the notebook either by fixing problems in existing code, or by adding your own solutions. Remember to push your changes to GitHub already while working, not only at the very end!\n", + "\n", + "- **Exercise 2 is due by 09:00 on 18.9.**\n", + "- Scores on this exercise are out of **20 points**.\n", + "\n", + "## Please note\n", + "\n", + "- **Some of the cells in this Jupyter Notebook are \"Read-only\" which means that you are not able to edit them.**\n", + "\n", + "- **Some of the code cells contain tests. If these tests fail, you know there is still something wrong with your code.**\n", + "\n", + "- **Some of the code cells raise** `NotImplementedError`. **This error tells you that you need to somehow modify that code cell.**\n", + "\n", + "\n", + "## Where to find help\n", + "\n", + "If you're having trouble, please remember you can\n", + "\n", + "- Come to the work sessions on Thursday and/or Friday for help from the course assistants\n", + "- Check out [the hints for this week's exercise](https://geo-python.github.io/site/lessons/L2/exercise-2.html) on the course webpage\n", + "- Post questions to Slack" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "0945eeb4936351eaf0d94e7eeda681b9", + "grade": false, + "grade_id": "cell-51a3fbb6b8d35c74", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "## Problem 0 - Cloning Exercise repository to JupyterLab (*0 points*)\n", + "\n", + "Before starting to work with the actual problems for this week, you should start a new JupyterLab instance and clone **your own** Exercise 2 repository (e.g. `exercise-2-htenkanen`) into the instance using **Git** as we saw in the [lecture this week](https://geo-python.github.io/site/lessons/L2/git-basics.html). " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "1e48e671ada57c103606dcff081e2f67", + "grade": false, + "grade_id": "cell-34d197ef67f874ec", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "## Problem 1 - Making changes to code and using Git (*7 points*)\n", + "\n", + "Your first task for this week is to make some modifications to the Python code in the cells below to fix the errors it gives once you run the code cells.\n", + "The code should allow users to find the operational time of an [FMI observation station](http://en.ilmatieteenlaitos.fi/observation-stations) by setting the `selected_station` variable.\n", + "*Don't worry about the case of a station name that is not on the list.*\n", + "\n", + "**The main aim is to print out an informative sentence that tells how long the selected station has been operational, for example** \n", + "\n", + "```\n", + "'The Helsinki Harmaja station has been operational for 30 years.'\n", + "```\n", + "or\n", + "```\n", + "'The Helsinki Kaivopuisto station has been operational for 115 years.'\n", + "```\n", + "\n", + "However, if you try to run all the code cells under Problem 1, you will run into errors. Your task is to find **3 things to fix** in the code cells under Problem 1. Once you succeed, the final print statement should work, and you should be able to modify the output only by setting a different station name.\n", + "\n", + "\n", + "### Grading for Problem 1\n", + "\n", + "Your score for this problem will be based on\n", + "\n", + "- Fixing **3 problems in the code** to get the code working as expected\n", + "- Committing each change separately to GitHub using Git\n", + "- Listing the changes you needed to make to get the code working in plain English by modifying the existing text or adding a Markdown cell above each change" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "ab9c79af966da5fb76c4ad608b1092ea", + "grade": false, + "grade_id": "cell-624ad911a29570ae", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "Here we create and fill lists of station names and starting years for observation.\n", + "**NOTE**: Long lines can be split into multiple lines using the \"\\\\\" character.\n", + "\n", + "*These code cells are \"Read-only\" - you won't be able to modify the input lists, but you still need to run them.*" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "4ac3f062a25698525019129839ce9911", + "grade": false, + "grade_id": "cell-f16d9e1598382abb", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "# Read-only code cell\n", + "station_names = ['Harmaja', 'Kaisaniemi', 'Kaivopuisto', 'Kumpula', 'lighthouse', \\\n", + " 'Malmi airfield', 'Suomenlinna aaltopoiju', 'Vuosaari harbour']" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "f032518a728ed6265d49f81a297405d8", + "grade": false, + "grade_id": "cell-a6fa30a83026c13c", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "# Read-only code cell\n", + "station_start_years = [1989, 1844, 1904, 2005, 2003, 1937, 2016, 2012]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "761974bf8be2a6cff3e58447802c0021", + "grade": false, + "grade_id": "cell-111a923765d7da38", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "Below we can define the selected station:" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "9254c6a4adf5b0423f1d442947675b10", + "grade": false, + "grade_id": "selected_station", + "locked": false, + "schema_version": 3, + "solution": true + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Harmaja\n" + ] + } + ], + "source": [ + "# YOUR CODE HERE\n", + "selected_station = input()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "241fe542d1b14c123a540aa9c0e5d577", + "grade": true, + "grade_id": "selected_station_test", + "locked": true, + "points": 1, + "schema_version": 3, + "solution": false + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Harmaja\n" + ] + } + ], + "source": [ + "print(selected_station)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "acb6b2147cd39c8522eaa4b39e396483", + "grade": false, + "grade_id": "cell-8c0ab6cf80173158", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "Next we find the location of the selected station in the list of station names:" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "09ba7c08752ddb3b990b9ac08069706a", + "grade": false, + "grade_id": "cell-4d559812a8644360", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "# Read-only code cell\n", + "station_index = station_names.index(selected_station)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "eafd36633edc38a9b0494d58e3cdad41", + "grade": false, + "grade_id": "cell-5b6020cf2c5808a6", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "Now we can calculate the years the station has been operational:" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "bcf3de34954938e8522f5e27960b6efd", + "grade": false, + "grade_id": "station_years", + "locked": false, + "schema_version": 3, + "solution": true + } + }, + "outputs": [], + "source": [ + "# YOUR CODE HERE\n", + "# station_index should be the index of station_start_years\n", + "station_years = 2019 - station_start_years[station_index]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "6e6842fd2b3547fda0eda04d242eeebc", + "grade": false, + "grade_id": "cell-a3782621daec92f2", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "\n", + "Now, we can print the station name and number of years of operation to the screen.\n", + "A sample print statement on screen is `'The Helsinki Harmaja station has been operational for 30 years.'` The print statements should work for all listed stations only by modifying the `selected_station` -variable that is defined earlier in this problem." + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "57c63db7d9a30090b281f69b7c8bb344", + "grade": false, + "grade_id": "print_statement", + "locked": false, + "schema_version": 3, + "solution": true + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Helsinki Harmaja station has been operational for 30 years.\n" + ] + } + ], + "source": [ + "# YOUR CODE HERE\n", + "# Syntax error solved\n", + "print_statement = \"The Helsinki \" + selected_station + \" station has been operational for \"+ \\\n", + " str(station_years)+ \" years.\"\n", + "\n", + "print(print_statement)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "608ef6eb22a40eb0008db66f1b5ce0b3", + "grade": false, + "grade_id": "cell-f26de00add515a66", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + } + }, + "source": [ + "#### Tests for problem 1\n", + "\n", + "Finally, we can run some tests to see if things are working as they should! These tests may help you in solving the problem. Note, we also run some hidden tests for checking the exercises. If these tests pass, it's not a quarantee of a 100 % correct answer!" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "c1476f92e71ae1258662e56cac344f49", + "grade": true, + "grade_id": "station_years_test", + "locked": true, + "points": 1, + "schema_version": 3, + "solution": false, + "task": false + } + }, + "outputs": [], + "source": [ + "# importing tools for running some tests\n", + "from nose.tools import ok_, assert_equal\n", + "\n", + "#Validate that station_years is a variable of integer type\n", + "assert_equal(type(station_years),int)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "87f94557c7bd2562bcbb461d7e11c9ab", + "grade": true, + "grade_id": "print_statement_test1", + "locked": true, + "points": 2, + "schema_version": 3, + "solution": false, + "task": false + } + }, + "outputs": [], + "source": [ + "#Validate that the print statement is correct for Harmaja station:\n", + "# Note! Your print statement should work for all the stations!\n", + "assert_equal(print_statement, 'The Helsinki Harmaja station has been operational for 30 years.')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "32fec0c1502a8011243a66d7373db890", + "grade": false, + "grade_id": "final_answer_question", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "#### Summarize what you did in problem 1 using markdown\n", + "\n", + "Describe the 3 code changes you made below in plain English (you can, for example, use bullet points here):" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "db6c917ce6aabe7be4930af01bcb4e79", + "grade": true, + "grade_id": "final_answer_question_test", + "locked": false, + "points": 3, + "schema_version": 3, + "solution": true + } + }, + "source": [ + "YOUR ANSWER HERE" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "74ac9031ca05899cd868c38c5bf85a54", + "grade": false, + "grade_id": "cell-f328c6e177c1d29c", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "## Problem 2 - Accessing monthly average temperatures (*9 points*)\n", + "\n", + "The table below presents [monthly average temperatures recorded at the Helsinki Malmi airport](https://www.timeanddate.com/weather/finland/helsinki/climate).\n", + "\n", + "| Month | Temperature [°C] |\n", + "| --------- | :--------------: |\n", + "| January | -3.5 |\n", + "| February | -4.5 |\n", + "| March | -1.0 |\n", + "| April | 4.0 |\n", + "| May | 10.0 |\n", + "| June | 15.0 |\n", + "| July | 18.0 |\n", + "| August | 16.0 |\n", + "| September | 11.5 |\n", + "| October | 6.0 |\n", + "| November | 2.0 |\n", + "| December | -1.5 |\n", + "\n", + "In the code cells below, write some Python code that allows users to select a month and have the monthly average temperature printed to the screen.\n", + "For example, your code should display the following for the month of March:\n", + "\n", + "```\n", + "The average temperature in Helsinki in March is -1.0\n", + "```\n", + "\n", + "### Grading for Problem 2\n", + "\n", + "Your score for this problem will be based on\n", + "\n", + "- Having your notebook display the monthly average temperature in a selected month, set by defining the variable `selected_month_index`.\n", + " - **NOTE**: We expect you to use the index value to select the month, not the name of the month (e.g., \"May\").\n", + "- Having it work for all 12 months in the year.\n", + "- Describe how your code works in a few sentences of plain English in the Markdown cell above your code\n", + "- Including inline comments to clearly explain how the code works between most and/or all lines of your code in its Python cell\n", + "- Pushing your script to your GitHub repository for this week's lesson." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "3da4af3cfd142ea4b7dbcebf08d9577a", + "grade": false, + "grade_id": "define_lists", + "locked": false, + "schema_version": 3, + "solution": true + } + }, + "outputs": [], + "source": [ + "# YOUR CODE HERE\n", + "raise NotImplementedError()\n", + "\n", + "# here is the variable which you use to set the selected month:\n", + "selected_month_index = None\n", + "\n", + "# Here are also the names of the two lists you should use for this problem. Please don't change the variable names!\n", + "months = None\n", + "average_temp = None\n", + "\n", + "# Using the lists and their indices, generate the desired print statement:\n", + "print_statement = None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "9f4a92d1a4cb196f35ec5232048e8c96", + "grade": true, + "grade_id": "define_lists_test", + "locked": true, + "points": 2, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "# Check your print statement:\n", + "print(print_statement)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "00b0dad83f1549ec4727cc3500504aef", + "grade": false, + "grade_id": "cell-3fb0ac91413aeadc", + "locked": true, + "schema_version": 3, + "solution": false, + "task": false + } + }, + "source": [ + "#### Tests for problem 2\n", + "\n", + "Let's run some additional tests to see if things are working as they should! These tests may help you in solving the problem. Note, we also run some hidden tests for checking the exercises. If these tests pass, it's not a quarantee of a 100 % correct answer!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "ce013efc8079071c431b866b5c587da2", + "grade": true, + "grade_id": "list_length_test", + "locked": true, + "points": 2, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "#Validate the length of two lists are 12\n", + "ok_(len(months)==12)\n", + "ok_(len(average_temp)==12)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "f564a96fc2712c98dd682cc64a8e2c3c", + "grade": true, + "grade_id": "list_type_test", + "locked": true, + "points": 2, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "#Validate that variable months and average_temp are lists\n", + "ok_(isinstance(months, list), 'Variable months is not a list')\n", + "ok_(isinstance(average_temp, list), 'Variable average_temp is not a list')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "code", + "checksum": "bc1cdf5456733ed168588635b8d81960", + "grade": true, + "grade_id": "print_statement_test", + "locked": true, + "points": 3, + "schema_version": 3, + "solution": false + } + }, + "outputs": [], + "source": [ + "#Validate the print statement is correct; \n", + "# Set selected_month_index to correspond with July before running this cell.\n", + "# Note! Your code should work with any of the 12 months!\n", + "assert_equal(print_statement, 'The average temperature in Helsinki in July is 18.0')\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "editable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "9c032326d744df32ab2628ff703a9c36", + "grade": false, + "grade_id": "markdown_practice", + "locked": true, + "schema_version": 3, + "solution": false + } + }, + "source": [ + "## Problem 3 - More practice using Markdown (*4 points*)\n", + "\n", + "The last task in this week's exercise is to answer some questions and add an image in this notebook using Markdown. **Note**: You may want to read a bit more about [formatting text in Github-flavored Markdown](https://help.github.com/articles/basic-writing-and-formatting-syntax/).\n", + "\n", + "\n", + "### Grading for Problem 3\n", + "\n", + "Your score for this problem will be based on\n", + "\n", + "- Your answers to the three questions that are part of this problem\n", + "- Posting an image of a favorite animal using Markdown\n", + "\n", + "\n", + "#### 1. Give your responses to these three questions about this week's lesson:\n", + "\n", + " - What did you learn?\n", + " - What was unclear?\n", + " - What would you change?\n", + " \n", + " *Please use Markdown lists when answering these questions.*\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "bada3cbd3bcc24069b24f4db7e13dcd1", + "grade": true, + "grade_id": "answer_questions", + "locked": false, + "points": 2, + "schema_version": 3, + "solution": true + } + }, + "source": [ + "YOUR ANSWER HERE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### 2. Adding an image\n", + "\n", + "Just for fun, add an image of an animal that you like along with a short caption giving its name and anything special you might like to add.\n", + "\n", + "You should add an image by linking to a website with the image, or if by uploading an image to your GitHub repository and linking to that (if you are looking for a challenge).\n", + "\n", + "We suggest that you search for images in a repository that includes licencing information such as [Wikimedia Commons](https://commons.wikimedia.org/wiki/Main_Page) or [Pixabay](https://pixabay.com/). You are, of course, also welcome to upload your own animal images. You can add it in a new Markdown cell under those used to answer the questions in part 1 of this problem." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": false, + "nbgrader": { + "cell_type": "markdown", + "checksum": "6bfc187e9555cb0dfa082b9960d1f1ff", + "grade": true, + "grade_id": "insert_image", + "locked": false, + "points": 2, + "schema_version": 3, + "solution": true + } + }, + "source": [ + "YOUR ANSWER HERE" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/README.md b/README.md index 8ea6123..05ea95f 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,6 @@ There are 3 problems and one preparatory step in this week's exercise: ## Start the exercise by opening **[this notebook](Exercise-2.ipynb)**. + +##Key Notes: +1. First changes in excercise file \ No newline at end of file