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)
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.
sports = ['cricket', 'football', 'volleyball', 'baseball', 'softball', 'track and field', 'curling', 'ping pong', 'hockey']
last = sports[-3:]
ActiveCode (assess_ac_2_1_1_2)
| Result | Actual Value | Expected Value | Notes |
|---|---|---|---|
| Pass | [‘cur…key’] | [‘cur…key’] | Testing that the value of last is the last three items in sports. |
| Pass | <__ma…ject> | True | Hardcode check |
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 by, az, io, or qy.
by = "You are"
az = "doing a great "
io = "job"
qy = "keep it up!"
message = by+" "+az+io+", "+qy
ActiveCode (assess_ac_2_1_1_3)
| Result | Actual Value | Expected Value | Notes |
|---|---|---|---|
| Pass | ‘You are’ | ‘You are’ | Testing original variables. |
| Pass | ‘doing a great ‘ | ‘doing a great ‘ | Testing original variables. |
| Pass | ‘job’ | ‘job’ | Testing original variables. |
| Pass | ‘keep it up!’ | ‘keep it up!’ | Testing original variables. |
| Pass | ‘You a…t up!’ | ‘You a…t up!’ | Testing that the value of message is what was expected. |
| Pass | ‘You a…t up!’ | ‘by = …+qy\n\n’ | Testing for hardcoding (Don’t worry about actual and expected values). |
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)
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]
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]
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(',')
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)