# CS8, 10F, H13, due Thu Lecture 11.18—Miller/Ranum, 5.2.5 (pp. 166-171), not and DeMorgan's Law—Total points: ?

 Name: (4 pts) Umail Address: (4 pts) @umail.ucsb.edu
 Lab Section (2 pts)—circle one: 9am 10am 11am noon unknown crashing
 You may collaborate with at most ONE other person on this homework assignment. If you do, please enter his/her name here: (He/she should also enter your name on her/his assignment.)

This assignment is due in Lecture on Thursday, 11.18.
It may ONLY be submitted in Lecture, at 2pm on Thursday.

You must come IN PERSON to turn it in during your assigned Lecture section.

The flip-side of this homework continues the reading in chapter 5, picking up where the previous homework assignment left off. Please read section 5.2.5 (pp. 166-171).

Note that Section 5.2.5 refers back to the measures of central tendency from Section 4.5 (mean, median, mode), and the Frequency Distribution code in Section 4.6 (pp. 146-149). Both of these, in turn use the Python concept of a "dictionary", which is a Python feature we have not studied so far in this course. Although you are welcome to read those if you want, it is not necessary to refer to these concepts to complete this homework.

This side of this homework has some more exercises related to the `not` operator and DeMorgan's laws (covered in lecture).

1. (20 pts) Please fill in the table below. The first column contains a Python expression involving the not operator

• Directly underneath each expression, fill in a Python expression that is equivalent to the first, without using the not operator.
• In the second column, fill in the value of the expression, assuming that w, x, y and z have the values shown.
under each expression,
fill in an equivalent expression
that doesn't use `not`
Value of expression when
w='ucsb'; x=6; y=2; z=[-3,-5]

` not type(z) != str`

type(z) == str

False

`  not (y > z[0])`

` not ( type(y)==int and len(w)>5 )`

` not ( type(z)!=list) or len(z)!=0 `

` not ( (x > y) or (y < 0) )`

` not (z[0] < y and y <= z[1]` )

...continued from other side

1. Section 5.2.5 describes using the techniques covered previously in Section 5.2 (which you may want to review) to compute some statistics with a real data file.

1. (5 pts) In listing 5.3, we have this line of code as line 7:
`maglist.append(float(vlist[0]))`

How would the list that is returned by makeMagnitudeList be different if the line read this way instead (without the use of the float() function:

`maglist.append(vlist[0])`

2. (5 pts) What is another way that line 7 could be written that uses the + operator (list concatenation)
instead of the `.append()` method?

2. (10 pts) Rewrite Listing 5.3 so that in addition to returning the list of magnitudes, it also writes them to a file called `"mag.txt"`, one per line. (You may want to review Section 5.2.2 before answering.)

Hint: You can do so by adding only three lines of code—and none of the code already in listing 5.3 has to be changed (except to add these three new lines.)

End of H13