|(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"
h01: Perkovic 2.1, 2.2 (Expr, Vars, Assignment, Strings)
|true||Mon 10/02 09:30AM||Tue 10/10 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 2.1, 2.2 (Expr, Vars, Assignment, Strings). Then complete these problems and turn in your completed homework during your registered lab section..
(10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class. It is important to fill in both name and umail every time, since handwriting is sometimes difficult to decipher. Having both helps us ensure you get credit for your work.
Also: while we strongly prefer that you submit your homework on a single sheet of paper, if you MUST submit it on multiple sheets, JUST write your name at the top of both sheets and turn in both sheets UNCONNECTED.
DO NOT staple, paper clip, spit-fold-and-tear, or do ANYTHING that would make it difficult to automatically feed your paper through a scanner.
Section 2.1 describes how several operators and built in functions in Python work. What would be the result of entering the following at the Python interactive shell prompt?
(Note: You are encouraged to check your answers at the Python prompt before turning in your work, but try this on paper first, just by reading the text and trying to predict what will happen. Then try typing in the results at the Python prompt. Change your answers if they were mistaken, but even more important, try to figure out why you were incorrect.)
Be very precise. Note that
Trueis not the same in Python as
true; upper vs. lower case matters. You will not get full credit for answers that are not precisely correct.
Points Expression Result Points Expression Result (4 pts)
2 + 3 * 5
4 < 3
19 % 3
1 + 2 == 3
5 ** 2
True and False
7 // 2
True or False
9 // 2
5 != 10//2
(5 pts) As described in section 2.1, a Python assignment statement contains the assignment operator, an expression and a variable, but not in that order.
What is the correct order for these three parts, reading from left to right?
(5 pts) Section 2.1 contains a list of thirty-three reserved words in Python that may not be used as the name of a variable. You don’t need to memorize this list, but you do need to know where to find it, either in the book, or online. So, to be sure you can find it, list all of the Python reserved words that start with the letter
Section 2.2 describes strings in Python, including the concepts of “dictionary order” (also called “lexicographic order”), concatenation of strings, multiplication of strings times an integer, the
not inoperation, the
lenfunction, and string indexing. Review that material.
Then, assuming the following assignment statements have been entered at the Python prompt:
school = "UCSB" course = "CS8" qtr = "F17"
Indicate the value of each of these expressions:
Expression Result Expression Result (4 pts)
school * 2
school > course
qtr < school
len(qtr) > 4
'D' in school
'E' not in school