Before you do ANYTHING, take out a scrap piece of paper. If I do not see your paper at the end of the lab, you will get 0 on this lab.
Run the below code and figure out what exactly is going on. I want to see everyone with paper here working through the logic. If you can’t figure it out, hack around with the code. Comment out bits. Print out bits. Do whatever you need to do to figure it out.
1a = [0, 0, 0] 2b = [a,a,a] 3 4for row in b: 5 toPrint = '' 6 for d in row: 7 toPrint += str(d) + ' ' 8 9 print(toPrint)
b = 1 to line 3 and run it again. Is this what you wanted? (no, it’s not). Fix this code such that the output will be what’s below. Hint: Change the list setup part, not the loops.
0 0 0 0 1 0 0 0 0
Change line 3
b = 1 and hit run. Did it do what you expected?
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
nums = [2, 7, 11, 15], target =
Think about how much work your algorithm for 3 had to do in terms of n, where n is the length of the list. Can you somehow think of a better algorithm that would do less work? Don’t spend too much time on this if you can’t come up with a solution. Just give yourself a fair chance. Hint: Dictionaries…
These are the same problems from last week. They’re good problems. Keep going. Start where you left off.
Grab a scrap piece of paper to start scratching your ideas down on paper. The problems are getting tricky enough where this really is becoming a requirement.
If you have somehow finished everything so far, go check out LeetCode. Sort the problems by Acceptance (click the table header) and start seeing if you can solve some of these problems.
ENSURE WE HAVE RECORDED YOUR COMPLETION. FAILURE TO DO SO WILL RESULT IN A GRADE OF 0!