Assessment: Way of the Programmer Week Four

Assessment: Way of the Programmer Week Four >> Python Basics

seqmut-1-1: Which of these is a correct reference diagram following the execution of the following code?

lst = ['mercury', 'venus', 'earth', 'mars', 'jupiter', 'saturn', 'uranus', 'neptune', 'pluto']
lst.remove('pluto')
first_three = lst[:3]
  1.  
First Potential Solution
  1.  
Second Potential Solution


✔️ Yes, when we are using the remove method, we are just editing the existing list, not making a new copy.

Multiple Choice (assess_question4_1_1_1)

Score: 1.0 / 1

 

seqmut-1-4: What will be the value of a after the following code has executed?

a = ["holiday", "celebrate!"]
quiet = a
quiet.append("company")

The value of a will be



Good work!

Fill in the Blank (assess_question3_3_1_1)

Score: 1.0 / 1

 

seqmut-1-5: Could aliasing cause potential confusion in this problem?

b = ['q', 'u', 'i']
z = b
b[1] = 'i'
z.remove('i')
print(z)

✔️ Yes, b and z reference the same list and changes are made using both aliases.

Multiple Choice (assess_question3_3_1_2)

Score: 1.0 / 1

 

seqmut-1-13: Given that we want to accumulate the total sum of a list of numbers, which of the following accumulator patterns would be appropriate?

  1.  
nums = [4, 5, 2, 93, 3, 5]
s = 0
for n in nums:
    s = s + 1
  1.  
nums = [4, 5, 2, 93, 3, 5]
s = 0
for n in nums:
    s = n + n
  1.  
nums = [4, 5, 2, 93, 3, 5]
s = 0
for n in nums:
    s = s + n



✔️ Yes, this will solve the problem.

Multiple Choice (assess_question5_2_1_1)

Score: 1.0 / 1

 

seqmut-1-14: Given that we want to accumulate the total number of strings in the list, which of the following accumulator patterns would be appropriate?

  1.  
lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]]
s = 0
for n in lst:
    s = s + n
  1.  
lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]]
for item in lst:
    s = 0
    if type(item) == type("string"):
        s = s + 1
  1.  
lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]]
s = ""
for n in lst:
    s = s + n
  1.  
lst = ['plan', 'answer', 5, 9.29, 'order, items', [4]]
s = 0
for item in lst:
    if type(item) == type("string"):
        s = s + 1




✔️ Yes, this will solve the problem.

Multiple Choice (assess_question5_2_1_2)

Score: 1.0 / 1

 

seqmut-1-15: Which of these are good names for an accumulator variable? Select as many as apply.





✔️Correct.
  1. Yes, total is a good name for accumulating numbers.
  2. Yes, accum is a good name. It’s both short and easy to remember.

Multiple Choice (assess_question5_2_1_3)

Score: 1.0 / 1

 

seqmut-1-16: Which of these are good names for an iterator (loop) variable? Select as many as apply.





✔️Correct.
  1. Yes, item can be a good name to use as an iterator variable.
  2. Yes, elem can be a good name to use as an iterator variable, especially when iterating over lists.
  3. Yes, char can be a good name to use when iterating over a string, because the iterator variable would be assigned a character each time.

Multiple Choice (assess_question5_2_1_4)

Score: 1.0 / 1

 

seqmut-1-17: Which of these are good names for a sequence variable? Select as many as apply.





✔️Correct.
  1. Yes, num_lst is good for a sequence variable if the value is actually a list of numbers.
  2. Yes, this is good to use if the for loop is iterating through a string.
  3. Yes, names is good, assuming that the for loop is iterating through actual names and not something unrelated to names.

Multiple Choice (assess_question5_2_1_5)

Score: 1.0 / 1

 

seqmut-1-18: Given the following scenario, what are good names for the accumulator variable, iterator variable, and sequence variable? You are writing code that uses a list of sentences and accumulates the total number of sentences that have the word ‘happy’ in them.





✔️ Yes, this combination of variable names is the clearest.

Multiple Choice (assess_question5_2_1_6)

Score: 1.0 / 1

 

For each character in the string saved in ael, append that character to a list that should be saved in a variable app.

 
ael = "python!"
lst = []
for i in ael:
lst.append(i)
app = lst
 
 

ActiveCode (access_ac_5_2_1_1)

Expand DifferencesExpand Differences

You passed: 100.0% of the tests

Score: 1.0 / 1

 

For each string in wrds, add ‘ed’ to the end of the word (to make the word past tense). Save these past tense words to a list called past_wrds.

 
 
 
 

ActiveCode (access_ac_5_2_1_2)

Expand DifferencesExpand Differences

You passed: 100.0% of the tests