1 |
e03 |
CS8 S18 |
Name: | ||
---|---|---|
(as it would appear on official course roster) | ||
Umail address: | @umail.ucsb.edu |
EXAM: e03: Final Exam
ready? | date | points |
---|---|---|
true | Thu 06/14 04:00PM |
You may not collaborate on this exam with anyone. If you need to use the restroom, you must leave your cell phone with the exam proctor before leaving the room.
- Write your name at the top of this page AND EVERY ODD NUMBERED PAGE.
- Double check that you turned in ALL pages; look for "End of Exam" on the last page.
- This exam is closed book, closed notes, closed mouth, cell phone off.
- You are permitted one sheet of paper (max size 8.5x11") on which to write notes.
- This sheet will be collected with the exam, and might not be returned.
- Please write your name on your notes sheet.
NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.
-
Indicate with a check ✓ what Python will return as the type of each expression.
Note that when Python reports a type, it reports it with expressions such as
<class 'int'>
and<class 'str'>
.I’m omitting the
<class '___' >
part to save space.-
(3 pts)
type({"foo":"bar"})
□str □ int □ float □ list □ tuple □ dict □ bool -
(3 pts)
type("[1]")
□str □ int □ float □ list □ tuple □ dict □ bool -
(3 pts)
type([1,2,3])
□str □ int □ float □ list □ tuple □ dict □ bool -
(3 pts)
type(4.5 * 2)
□str □ int □ float □ list □ tuple □ dict □ bool -
(3 pts)
type( 1+2==3 )
□str □ int □ float □ list □ tuple □ dict □ bool
-
-
Please find both Handout A and Handout B.
- p.1 of Handout A shows some code based on lab08, where we worked with lists of lists to represent a screen.
- p. 2 shows a variety of sample outputs that could result from various function calls, labelled 1-13.
For each of the function calls below (all based on the code shown on Handout A), please select which of the outputs shown on Handout B will result. Simply write the number, 1 through 13 to indicate the correct output.
number/points function call your selection (1-13)
from Handout B(a) (3 pts) print_screen(create_screen(3,4))
(b) (3 pts) print_screen(create_screen(4,4))
(c) (3 pts) print_screen(create_screen(4,3))
(d) (3 pts) isla()
(e) (3 pts) vista()
(f) (3 pts) foo()
(g) (3 pts) bar()
(h) (3 pts) baz()
-
Complete each of the number conversions shown:
(a) (3 pts) Convert 0110 1110 1101 0011 from binary to base 16 final answer only in box above (b) (3 pts) Convert 141 from decimal to binary final answer only in box above (c) (3 pts) Convert 644 from octal to base 2 final answer only in box above -
Complete each of the number conversions shown:
(a) (3 pts) Convert 1010 0010 from base 2 to base 10 final answer only in box above (b) (3 pts) Convert 1101 0010 1100 0100 from binary to base 16 final answer only in box above -
Complete each of the number conversions shown:
(a) (3 pts) Convert 82 from decimal to binary final answer only in box above (b) (3 pts) Convert 1011 0100 from binary to decimal final answer only in box above (c) (3 pts) Convert 3ad9 from base 16 to base 2 final answer only in box above -
(3 pts) What is the Unix command that shows you all the files and folders in your current directory?
-
(3 pts) What is the Unix command that creates a new folder/directory for you to store files in?
-
(4 pts) In the context of using
pytest
to run tests, what does the output..FF...F.
mean? (For full credit, be as specific as possible). -
(6 pts) Fill in one line of code to complete the function so that it corretly computes the sum of the numbers in a list using a for loop.
def sumList(aList): total = 0 for a in aList: ________________ return total
-
(6 pts) Fill in one line of code to complete the function so that it corretly computes the sum of the numbers in a list using recursion.
def sumList(aList): if aList==[]: return 0 else _________________
-
(6 pts) Fill in the blank so that the function returns the first even integer in the list. You may ignore the possibility of errors; that is you may assume that
aList
is of typelist
and all the values in the list are of typeint
.If there is no even integer in the list, the function should return
None
.def indexOfFirstEven(aList): for i in range(len(aList)) if _______________________: return i return None
-
(9 pts) Fill in the three blanks so that the function returns a list containing only the strings from the list passed in.
For example:
onlyStrings([3,"foo","bar",5,"6"]
returns["foo","bar","6"]
def onlyStrings(alist): result = ________ for ________________: if type(x)==str: _____________________ return result