CIS 41A Unit C, Problem C

This assignment consists of two scripts.

At the top of each of your scripts, put the following multi-line comment with your information:

'''
Your name as registered, with optional nickname in parentheses
CIS 41A   Fall 2021
Unit C, Problem C
'''

First Script – Working with Lists

All print output should include descriptions as shown in the example output below.
  1. Create an empty list called list1
  2. Populate list1 with the values 1,3,5
  3. Swap the second and third elements of list1.
  4. Iterate over list1 and print its items.
  5. Create list2, initialized with the values 1,2,3,4
  6. Create list3 by combining list1 and list2 (use the + operator).
  7. Print list3.
  8. Use sequence operator in to test list3 to see if it contains a 3, print True/False result (do with one line of code).
  9. Count the number of 3s in list3, print the result.
  10. Determine the index of the first 3 in list3, print the result.
  11. Pop this first 3 and assign it to a variable called first3, print first3.
  12. Create list4, populate it with list3's sorted values, using the sorted built-in function.
  13. Print list3.
  14. Print list4.
  15. Slice list3 to obtain a list of the values 1,2,3 from the middle of list3, print the result.
  16. Determine the length of list3, print the result.
  17. Determine the max value of list3, print the result.
  18. Sort list3 (use the list sort method), print list3.
  19. Create list5, a list of lists, using list1 and list2 as elements of list5.
  20. Print list5.
  21. Print the value 4 contained within list5.

Example output:

d) Items in list1:
1
5
3
g) list3 is: [1, 5, 3, 1, 2, 3, 4]
h) list3 contains a 3: True
i) list3 contains 2 3s
j) The index of the first 3 contained in list3 is 2
k) first3 = 3
m) list3 is now: [1, 5, 1, 2, 3, 4]
n) list4 is: [1, 1, 2, 3, 4, 5]
o) Slice of list3 is: [1, 2, 3]
p) Length of list3 is 6
q) The max value in list3 is 5
r) Sorted list3 is: [1, 1, 2, 3, 4, 5]
t) list5 is: [[1, 5, 3], [1, 2, 3, 4]]
u) Value 4 from list5: 4

Second Script – Bit Operators

  1. Assign the values 9 and 14 to variables a and b respectively.
  2. Print the binary values of a and b (use the bin built-in function).
  3. Calculate the value of a and b, print the result in binary.
  4. Calculate the value of a or b, print the result in binary.
  5. Examine the results. Can you see how they were arrived at?

Example output:

b) binary of a =  0b1001
b) binary of b =  0b1110
c) binary of a & b =  0b1000
d) binary of a | b =  0b1111

Add the following at the end of each script to show your results:

'''
Execution results:
paste execution results here
'''

Submit both your finished py scripts in Canvas, Problem C.