1
h01
CCS CS20 S18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu
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)

ready? assigned due points
true Tue 04/17 12:30PM Thu 04/19 12:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

This assignment should be submitted by scanning the pages in the correct order to a PDF file and uploading to gradescope.com.

For more information, visit ucsb-cs8.github.io and look for Gradescope: Student Self Submission under "topics".

Even though it is a Gradescope submission, nevertheless, *please fill in the information at the top of this homework sheet*, including your name and umail address.


READING ASSIGNMENT

Please read Perkovic 2.1, 2.2 (Expr, Vars, Assignment, Strings). Then complete these problems.

  1. (10 pts) These 10 points are for filling in your name at the top of the sheet, and scanning correctly on Gradescope. (Having these here gives me a place to give you feedback if there is some glitch with the way you are doing it.)

  2. 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 True is 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 pts) 4 < 3  
    (4 pts) 19 % 3   (4 pts) 1 + 2 == 3  
    (4 pts) 5 ** 2   (4 pts) True and False  
    (4 pts) 7 // 2   (4 pts) True or False  
    (4 pts) 9 // 2   (4 pts) 5 != 10//2  
  3. (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?

  4. (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 c or f.

  5. 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 in operator, the not in operation, the len function, and string indexing. Review that material.

    Then, assuming the following assignment statements have been entered at the Python prompt:

    school = "UCSB"
    course = "CS8"
    qtr = "M17"
    

    Indicate the value of each of these expressions:

      Expression Result     Expression Result
    (4 pts) school * 2     (4 pts) school > course  
    (4 pts) qtr[1:3]     (4 pts) qtr < school  
    (4 pts) course[0:2]     (4 pts) len(qtr) > 4  
    (4 pts) 'D' in school     (4 pts) school[-1]  
    (4 pts) 'E' not in school     (4 pts) school[0]