GGR274 Lab 2: Introduction to Programming, Part 1#
Logistics#
Like last week, our lab grade will be based on attendance and submission of a few small tasks to MarkUs during the lab session (or by 23:59 on Thursday).
Complete the tasks in this Jupyter notebook and submit your completed file to MarkUs. Here are the instructions for submitting to MarkUs (same as last week):
Download this file (
Lab_2.ipynb
) from JupyterHub. (See our JupyterHub Guide for detailed instructions.)Submit this file to MarkUs under the lab2 assignment. (See our MarkUs Guide for detailed instructions.)
Note (Updated 2024): you can use autotests with this week’s lab to see if you are on the right track. Your TA and instructors can look in more detail to see if you answered all questions. The submission is a part of your Lab attendance grade.
Task 1a: Reviewing Python data types#
The table below shows a few different Python values. Your task is to fill in the second column to write down the name of the Python data type that corresponds to each value.
To “fill in the table”, double-click on this cell and edit the text in the table. We’ve done the first row for you.
Value |
Data type |
---|---|
|
|
|
|
|
|
|
|
|
Task 1b: Reviewing Python operations and data types#
Based on part I of the lecture, fill in the gaps AND write down another 2-3 examples of operations you know now, data types you can apply them to and examples of use (you don’t have to cover all of them, but this is a good way to revise)
Operation |
Applied to type … |
Results is of type … |
Example |
---|---|---|---|
|
|
|
…. |
|
|
|
|
|
|
||
… |
Can some functions or operators be aplied to other types? Experiment :)
Task 2: Assigning variables#
In the code cell below, use assignment statements to define the following four variables:
name
: your full nameage
: your age, in yearslikes_python
: a boolean representing whether or not you like Python so far (any value is acceptable!)courses
: a list of the course codes (e.g. GGR274) that you are enrolled in this semester
Then, print out each of the four variables.
# write your code here
Task 3: Some computations#
Part (a)#
Suppose you’re taking a course with the following grading scheme:
Assessment |
Weight |
---|---|
Test 1 |
20% |
Test 2 |
15% |
Final Project |
35% |
Final Exam |
30% |
Now suppose you’ve received the following marks in the course:
Test 1: 28/30
Test 2: 23/30
Final Project: 75/100
Final Exam: 77/100
In the cell below, write Python code to calculate and print out your final grade in the course. Note: your final grade should be rounded to the nearest integer.
# Write your code here!
Part (b)#
In the cell below, we’ve defined a variable containing the text of Prime Minister Trudeau’s 2021 speech marking the first National Day for Truth and Reconciliation.
It’s the longest piece of data we’ve seen the course so far, so please just run the cell for now and then continue reading below.
speech = "Good evening.\n\nLet me begin by acknowledging that we are on the traditional territory of the Algonquin People who we recognize as past, present, and future caretakers of this land.\n\nThank you Elder Commanda for your words, for your leadership, for your prayers, for gathering us here today on this beautiful land.\n\nThank you Grand Chief McGregor for your leadership, for your strength, and for representing not just leadership but youth as we look to the future and acknowledge the past.\n\nThank you Elder Celine for your words, and for sharing your heartbreaking story. It couldn’t have been easy to tell so I applaud your courage. It’s hard to hear that this is the history of our country.\n\nRight now, we are in this place that has so much history for our country. This is where we celebrate Canada Day, and we talk about a country of peace, rights, and openness to the world. But we must also remember that our country has made terrible mistakes.\n\nElder Levina, as you shared your words and recognized the teddy bears and empty shoes, thank you for your leadership. And thank you for that reflection. That all of us – all of us – need to hold these stories in our hearts, in our understanding not just as we reflect on reconciliation, but as we reflect on this country. This country we all grew up in, this country we live in, but mostly this country we choose to create every single day.\n\nElder Jimmy Durocher, you reminded us that the stories we tell about ourselves, about our communities, the stories we tell our children and grandchildren as we tuck them into bed about who they are, about where they come from, or what they might be later in life are incredibly important. And on this day we celebrate and mark and commemorate tomorrow – the National Day for Truth and Reconciliation – we must reflect not just on those children ripped from their homes, from their communities, from their language, from their culture, from their moms and dads who didn’t get to hear the stories of who they were or of what they might be.\n\nWe must also take tomorrow and every day as a moment to remember and to reflect on the stories we tell about who we are as people who share this land, as Canadians. All people are good at telling stories of how great we are, of how we were heroic in this moment or there were brave leaders in other moments. It’s harder to reflect on the truth, on the mistakes, on the evil that we did in the past, but that’s what this day, this day of truth and reconciliation must be. To recognize the truth that this country in its past was responsible for terrible injustices. But that it’s not just about the past. That reconciliation is understanding that that legacy of the past that we were so painfully reminded of, that so many non-Indigenous Canadians discovered with the graves discovered in Kamloops and in Cowessess. This shock and dismay that so many non-Indigenous Canadians felt when they heard these stories and saw these images of unmarked graves of children. For Indigenous peoples across this country, it was a terrible blow not because it was a surprise because families across this country remember all too well the stories of aunties and uncles, family members taken from their homes, taken from their communities, so many of them never to return. But it was a reopening of old wounds, a hint of perhaps a hope of closure and putting names and stories to those losses.\n\nWe must reflect on the fact that reconciliation is not just a matter of looking back and understanding the mistakes of the past. It’s also about understanding that those mistakes are still shaping us today. The systemic racism that cost Joyce Echaquan her life. The hardships, the poverty, and the terrible challenges that Indigenous communities and Indigenous peoples are still going through across our country today because of things done decades and generations ago. That is also our responsibility as a country.\n\nEven as we look at truth and reconciliation as not just the past, not just the present of injustice, inequality, discrimination, and racism that we live still far too often in this country every single day – reconciliation is about a choice we make for the future. We condemn the residential schools across the country, schools that tried very hard to erase the Indian in the child, to take from Indigenous peoples, their language, their culture, but more their families, their sense of communities. At the same time as those schools were telling Indigenous peoples that they had no worth, no value in their culture, every other school in this country was teaching the same thing to non-Indigenous children. That the languages, the culture, the identity of Indigenous peoples had no worth, had no value in this country.\n\nThat is the legacy. That is the truth that we need to mark tomorrow and every day.\n\nSo do not tell me or try to explain that the National Day for Truth and Reconciliation is a day for Indigenous Canadians. It is a day for all Canadians. It is all of us. It is all of our story. Because if we do not just recognize the truth, but also understand the truth and bring it into ourselves and then bring it into every action we take every day as we live with intention, with mindfulness about what we bring and what we shape with our words, with our choices throughout our lives, then we’re not understanding the lessons of the past that we must acknowledge and learn from.\n\nIndigenous peoples in this country have so much to teach us about patience, openness, and understanding of a long-term vision for inhabiting this beautiful planet. This is our responsibility to future generations. But we also have to learn about ourselves, as a society, that did not leave them any room in this magnificent land of Canada that they were always ready to share with us all.\n\nSo tomorrow, all of you here tonight, all of you reflecting on this at home, and all of you as you go about your daily lives, take a moment to listen to the stories of a survivor, to an Indigenous elder who shares their perspective and their experiences in this country. And know that that story, their story, is your story as well. And until we understand as a country that each one of our stories is all of our stories, there can be no truth. There can be no reconciliation.\n\nSo tomorrow and in all the days to come, we will reflect on how each and every one of us can contribute to a better country. And on that shared vision of a better world through truth and reconciliation.\n\nMerci.\n\nThank you.\n\nGilakas’la.\n\nNakummek.\n\nMashi cho\n\nMiigwetch\n\nKinanaskomitinow."
In the cell below, do the following:
Use the
str.split
method to break up the speech text into words. (This will also get rid of the “\n
”, which is a special character representing a line break in the text.)Count the number of words in the text. This can include strings like
'-'
, since those will also be separated out when you callstr.split
.Use the (new!)
list.count(value)
method to count the number of times the word"Indigenous"
appears in the speech.
We recommend using the print()
function to output the values from your code cell.
# Write your code here!
Task 4: Your music tastes#
In the cell below:
write into list
my_tastes
how much do you like the music of the following artists (let’s use -5 to +5 scale, -5 absolutely can’t stand, 0 - idk/neutral, +5 on repeat, actually listening right now):Drake, Tame Impala, Billie Eilish, The Weeknd, Taylor Swift
assign your name to variable
my_name
my_tastes = [...]
my_name = "..."
Experiment more!
Write down the same for one of your friends or family members (or make up an imaginary friend) to the list
tastes2
Think how to answer based on this data:
How (comparatively) enthusiastic about music you and your friend are?
How would you approach comparing music tastes between two people?
Write down your ideas first and then you can try to put it into code (it does not have to work)!
My ideas…
#My code to experiment...