1 |
h10 |
CS8 M19-B |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section |
||
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 (Character Encodings)- 6.4 (Random)
ready? | assigned | due | points |
---|---|---|---|
true | Tue 08/27 02:00PM | Tue 09/03 02:00PM |
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,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the lowest scores (if you have zeros, those are the lowest scores.)
READING ASSIGNMENT
Please read Perkovic 6.3 (Character Encodings)- 6.4 (Random). Then complete these problems and turn in your completed homework in lecture on the due date.
(10 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
utf-8
,utf-16
, andutf-32
.-
(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 toprint
makes the print NOT go to a new line; instead, it just prints a space after eachcall toprint
(See Section 4.2, p. 99 in the textbook.)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=",")
(5 pts) print ('\u0048\u0049\u0021')
(5 pts) -
(10 pts) Write a Python expression that returns an random integer between 5 and 10.
-
Suppose the python variable
ucList
is 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
ucList
is already in lexicographic order, though if it were not, we could put it in lexicographic order by writingucList.sort()
.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.
-