Assessment: Lists and Strings

Assessment: Lists and Strings >> Python Basics

sequences-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)




✔️ Yes, because let_two was put before let, c has “pz” and then that is repeated five times.

Multiple Choice (assess_question2_1_1_1)

Score: 1.0 / 1

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.

 

ActiveCode (assess_ac_2_1_1_2)

Expand DifferencesExpand Differences

You passed: 100.0% of the tests

Score: 1.0 / 1

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 byazio, or qy.

 
 

ActiveCode (assess_ac_2_1_1_3)

Expand DifferencesExpand Differences

You passed: 100.0% of the tests

Score: 1.0 / 1

sequences-10-2: What will the output be for the following code?

ls = ['run', 'world', 'travel', 'lights', 'moon', 'baseball', 'sea']
new = ls[2:4]
print(new)



✔️ Yes, python is a zero-index based language and slices are inclusive of the first index and exclusive of the second.

Multiple Choice (assess_question2_1_1_4)

Score: 1.0 / 1

sequences-10-3: What is the type of m?

l = ['w', '7', 0, 9]
m = l[1:2]



✔️ Yes, a slice returns a list no matter how large the slice.

Multiple Choice (assess_question2_1_1_5)

Score: 1.0 / 1

sequences-10-4: What is the type of m?

l = ['w', '7', 0, 9]
m = l[1]



✔️ Yes, the quotes around the number mean that this is a string.

Multiple Choice (assess_question2_1_1_6)

Score: 1.0 / 1

sequences-10-5: What is the type of x?

b = "My, what a lovely day"
x = b.split(',')



✔️ Yes, the .split() method returns a list.

Multiple Choice (assess_question2_1_1_7)

Score: 1.0 / 1

sequences-10-6: What is the type of a?

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.