In the “Taste of Python” lesson this week we have learned a few basic things in Python. Now you get your chance to demonstrate your skills.
This exercise is inspired by Finland being ranked the world's happiest country for the 6th year in a row. As the instructors of the Geo-Python course, we think we've found a better way to assess the individual happiness of people in Finland (particularly those taking this course!), and we're going to test our idea with you. In five easy steps (or problems) we'll be able to reveal your happiness based on two of life's most important happiness factors: Ice cream and sleep!
Before you get started with the exercise, we ask that you please fill out the Geo-Python/AutoGIS pre-course survey at https://elomake.helsinki.fi/lomakkeet/125237/lomake.html. Your responses will help shape how we teach this autumn!
-
Open Jupyter lab from the Exercise 1 landing page on the course site and create a new notebook.
-
Use the file browser on the left side of the Jupyter Lab window to change the name of your notebook file to
Exercise-1.ipynb
.
In the top cell of the new notebook:
-
Create a variable called
ice_cream_rating
and use it to store an integer value (whole number) between 0 and 10 that reflects your general opinion about how much you enjoy eating ice cream. -
Create another variable called
sleeping_rating
and use it to store another integer between 0 and 10 that reflects your opinion about how much you enjoy sleeping. -
Run the cell by pressing Shift + Enter.
In the new cell that appears:
-
Store your first name as a character string in a variable called
first_name
. -
Store your last name as a character string in a variable called
last_name
. -
(Optional) Define a third variable called
my_name
that will combine your first and last names into a single character string with a space between the names. -
Run the cell by pressing Shift + Enter.
In order to assess your overall happiness it is necessary to combine the ice cream and sleeping ratings. To do this:
-
Calculate the average of your
ice_cream_rating
andsleeping_rating
variables and store the resulting value in a variable calledhappiness_rating
. -
Run the cell by pressing Shift + Enter.
The next step is to investigate the kinds of data we're working with. In another Python cell:
-
Use a built-in Python function to check the data types of the
ice_cream_rating
,first_name
, andhappiness_rating
variables. In order to see the data types for more than one variable in a single Python cell, you will need to print out these values using another built-in Python function. -
Run the cell by pressing Shift + Enter.
-
Did all of the data types make sense? Were there any data types that were different than you expected? In the new Python cell that appeared after running the code above, type in your responses to these questions.
-
For the cell containing your answers to the questions above, change the kind of cell from Code to Markdown.
-
Run the Markdown cell by pressing Shift + Enter.
Finally, you can use your Python skills to generate output on the screen similar to that below. Use one command to generate each line of output.
My name is Dave and I give eating ice cream a score of 9 out of 10!
I am Dave Whipp and my sleeping enjoyment rating is 8 / 10!
Based on the factors above, my happiness rating is 8.5 out of 10, or 85.0 %!
Note that your code should replace “Dave” with the contents of your first_name
variable, “9” with your value stored in the variable ice_cream_rating
, etc. For your equivalent text with the full name (e.g., "Dave Whipp"), you can either use the values from the variables first_name
and last_name
, or the value in variable my_name
.
To complete this exercise, download your notebook to your computer and upload it to GitHub in your own Exercise 1 repository that you created using the GitHub Classroom link.