CSE 8A

CSE 8A: Worksheet 4 Name:
Due: Nov 3 at 11:59pm PID:
Late Deadline: Nov 5 at 11:59pm UCSD Email:
NOTE: Please add your name in all the pages of your submission. Please make sure to carefully read the
submission instructions given here: Worksheet Submission Instructions.
1. a) What are the elements in places after these lines of code execute Write out the entire list.
b) What are the elements in courses and new_courses after these lines of code execute Write out both the
lists. [NOTE: The str.upper() method returns a string where all characters of str are in upper case. For example,
“abc123”.upper() will return “ABC123”.]
2. Please refer to Stepik Lesson 4.2 for details about pop(), index(), and reverse().
a) Rearrange the following lines of code such that sentence = “PA 3.,on,working,I’m” is
modified to become sentence = “I’m currently working on Worksheet 4.”
No. Lines Rearranged
1 sentence_list.reverse()
2 sentence_list.insert(1,”currently”)
3 sentence = ” “.join(sentence_list)
4 sentence_list.pop()
5 sentence_list = sentence.split(“,”)
6 sentence_list.append(“Worksheet 4.”)
CSE 8A: Worksheet 4 Name:
Due: Nov 3 at 11:59pm PID:
Late Deadline: Nov 5 at 11:59pm UCSD Email:
b) Vardhan is grading an exam and stores the points in a list. He realizes that he incorrectly gave 0s instead
of 1s for some answers. So, he wants to change both the 0s to 1s in the points list so that the modified
points list contains [2, 4, 1, 5, 1]. He decided to fix the problem by writing the code below. Has Vardhan
solved the problem Why/why not Explain your answer.
3. Harry Potter has broken his glasses… yet again. He needs to cast the spell Reparo! to fix his glasses.
Look at the code below, and draw the call stack right before line 6 is executed. Draw the global stack frame
and other stack frames for functions (if any) and clearly write the variables (and parameters) and their
values within each of these frames.
CSE 8A: Worksheet 4 Name:
Due: Nov 3 at 11:59pm PID:
Late Deadline: Nov 5 at 11:59pm UCSD Email:
4. What will be the output of the below code snippet Explain your answer.