Skip to main content
Contents
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 8.10 Chapter Assessment
Checkpoint 8.10.1 .
What will the output be for the following code?
let = "z"
let_two = "p"
c = let_two + let
m = c*5
print(m)
The order of concatenation matters.
Think about the order that the program is executed in, what occurs first?
Yes, because let_two was put before let, c has "pz" and then that is repeated five times.
Think about the order that the program is executed in, what occurs first?
None of the above, an error will occur.
This is correct syntax and no errors will occur.
Checkpoint 8.10.2 .
Write a program that extracts the last three items in the list
sports
and assigns it to the variable
last
. Make sure to write your code so that it works no matter how many items are in the list.
Checkpoint 8.10.3 .
Write code that combines the following variables so that the sentence βYou are doing a great job, keep it up!β is assigned to the variable
message
. Do not edit the values assigned to
by
,
az
,
io
, or
qy
.
Checkpoint 8.10.4 .
What will the output be for the following code?
ls = ['run', 'world', 'travel', 'lights', 'moon', 'baseball', 'sea']
new = ls[2:4]
print(new)
[βtravelβ, βlightsβ, βmoonβ]
When we take a slice of something, it includes the item at the first index and excludes the item at the second index.
[βworldβ, βtravelβ, βlightsβ]
When we take a slice of something, it includes the item at the first index and excludes the item at the second index. Additionally, Python is a zero-index based language.
[βtravelβ, βlightsβ]
Yes, python is a zero-index based language and slices are inclusive of the first index and exclusive of the second.
[βworldβ, βtravelβ]
Python is a zero-index based language.
Checkpoint 8.10.5 .
l = ['w', '7', 0, 9]
m = l[1:2]
Not quite, is it slicing or accessing an element?
What is happening in the assignment statement for m?
What is happening in the assignment statement for m?
Yes, a slice returns a list no matter how large the slice.
Checkpoint 8.10.6 .
l = ['w', '7', 0, 9]
m = l[1]
Yes, the quotes around the number mean that this is a string.
Not quite, look again at what is being extracted.
Not quite, look again at what is being extracted.
Not quite, is it slicing or accessing an element?
Checkpoint 8.10.7 .
b = "My, what a lovely day"
x = b.split(',')
Not quite; .split() returns a list, each of whose elements is a string.
Not quite, look again at what types are present and what the result of .split() is.
Not quite, look again at what types are present and what the result of .split() is.
Yes, the .split() method returns a list.
Checkpoint 8.10.8 .
b = "My, what a lovely day"
x = b.split(',')
z = "".join(x)
y = z.split()
a = "".join(y)
Yes, the string is split into a list, then joined back into a string, then split again, and finally joined back into a string.
Not quite, look again at what types are present and what the result of .split() is.
Not quite, look again at what types are present and what the result of .split() is.
Not quite, think about what .split() and .join() return.
Checkpoint 8.10.9 .
Write code to determine how many 9βs are in the list
nums
and assign that value to the variable
how_many
. Do not use a for loop to do this.
Checkpoint 8.10.10 .
Write code that uses slicing to get rid of the the second 8 so that here are only two 8βs in the list bound to the variable nums.
Checkpoint 8.10.11 .
Assign the last element of
lst
to the variable
end_elem
. Do this so that it works no matter how long lst is.
Checkpoint 8.10.12 .
Assign the number of elements in
lst
to the variable
num_lst
.
Checkpoint 8.10.13 .
Create a variable called
wrds
and assign to it a list whose elements are the words in the string
sent
. Do not worry about punctuation.
You have attempted
of
activities on this page.