|(as it would appear on official course roster)|
| Optional: name you wish to be called|
if different from name above.
| Optional: name of "homework buddy"|
(leaving this blank signifies "I worked alone"
h10: Perkovic 6.3-6.4 (Encodings, random)
|true||Tue 11/07 08:00AM||Tue 11/14 08:00AM|
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE.
There is NO MAKEUP for missed assignments, and you may not submit work in advance, or on behalf of another person.
In place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores.)
Please read Perkovic 6.3-6.4 (Encodings, random). Then complete these problems and turn in your completed homework during your registered lab section..
( pts) Please fill in the information at the top of this homework sheet, as usual. WRITE DARK, and remember, if you MUST submit it on multiple sheets, JUST write your name at the top of both sheets and turn in both sheets UNCONNECTED. No staples, paper clips, fold/tear etc or anything that would jam up the scanner.
Section 6.3 discusses character encodings, a topic that usually arises in the context of dealing with strings, and files. Two encodings are discussed: ASCII and Unicode. The text also discusses various ways of representing Unicode characters including
(10 pts) The original 7-bit ASCII character set has 128 different characters, numbered 0 through 127, but not all of them are “printable” characters. According to our text, how many of the ASCII characters with codes 0 through 127 are considered “printable”?
(10 pts) Fill in the blanks in the following sequence of Python code so that the code prints out all of the lowercase characters ‘a’ through ‘z’:
a b c d e f g h i j k l m n o p q r s t u v w x y z
Your answer should only involve filling in the blanks; not modifying the rest of the code in anyway. As a reminder,
end=' 'on a function call to
for i in range ( ________ , ________ ) : print(chr(i),end=' ')
Indicate what the output of the code will be:
for c in "UCSB": print(ord(c),sep=",")
(10 pts) Write a Python expression that returns an random integer between 5 and 10.
Suppose the python variable
ucListis defined as follows:
ucList=[ "UCB", "UCD", "UCI", "UCLA", "UCM", "UCR", "UCSB", "UCSC", "UCSD" ]
(10 pts) Write a Python expression that returns the name of a random UC from this list (as a string). For full credit, use the most straightforward way (that way doesn’t involve calculating the length of the list.)
(10 pts) Write a Python expression that returns a pair of random UCs from this list (i.e. a list of length 2 that has two randomly selected UCs from the list. Do it in the most straightforward way possible. (If you read the whole section carefully, you’ll discover this can be done in one line of code.)
(10 pts) Section 6.3 explains the idea of lexicograpic order. As it turns out, the list
ucListis already in lexicographic order, though if it were not, we could put it in lexicographic order by writing
What is lexicographic order?
(20 pts) Suppose that someone proposed that instead of putting the UCs in alphabetical order, to randomize the order (so that “UCB” wouldn’t always be first, and “UCSD” wouldn’t always be last.)
Write some Python code that would print the UC abbreviations, one per line, in a random order. Use the most straightforward way of doing it.