CS8, 09M, UCSB
H03: (Based on Miller/Ranum, Chapter 2 and Chapter 3) Total points: ? (printable PDF)
Accepted: on paper, in lecture (11am-12:25pm, Harold Frank Hall 1132 (note room change) ) on Tuesday, August 11th
No email submission allowed.
Name: (3 pts)______________________________ UCSBNetID (3 pts) _____________________
Lab Section (2 pts) Circle one: Thu 11am Thu 12:30pm Unknown
Circle the one you plan to attend, which may or may not be the one you are registered for.
To answer the questions on this homework, it will be very helpful to have a computer system running Python 3.0 or Python 3.1 available to you. To find such as system, you can either:
- log on to one of the computers in the CSIL computer lab, and access Python 3.0 or Python 3.1 there
- download Python 3.0 or Python 3.1 to your PC or Mac, and access Python 3.0 or Python 3.1 there
You can find more information about how to access these systems on the course web site under the "topics" link.
Review Chapters 2 and 3 in your textbook, then answer these questions:
- (5 pts) Section 3.2.3 talks about the index operator. What symbol is used for the index operator?
- (5 pts) Section 3.2.4 talks about the slice operator. What symbol is used for the slice operator?
- If we write this at the Python shell prompt:
>>> team = "Gauchos"
then type each of the following at the shell prompt, what will the result be?
- (3 pts) >>> team[0]
- (3 pts) >>> team[0:2]
- (3 pts) >>> team[-1]
- (3 pts) >>> team[1:3]
- (10 pts) Read Section 3.2.5. Then answer:
There is a "string method "that will convert the variable team to all capital letters, i.e. return GAUCHOS instead of gauchos?
What do we write if we want to assign the varible teamUC to be team, converted to upper case?
Hint: The correct answer is NOT teamUC = "GAUCHOS"
Please turn over for more problems
Continued from other side
- (10 pts) (problem 2.3 from page 81 in the textbook.)
Write a function to compute the area of a circle with a radius of r. Use n as the parameter to the function. Use the value of π from the math module.
End of H03