CS8, 10F, H03, due Tue Lecture 10.05—Miller/Ranum 2.1-2.5 (thru p. 45-61).—Total points: ?

Available online as http://www.cs.ucsb.edu/~pconrad/cs8/10F/homework/H03—printable PDF

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.)

(Note: For now, circle the lab section you are registered for on GOLD. If you need to request attendance at a different lab section because of an ACTUAL SCHEDULE CONFLICT, please email pconrad@cs.ucsb.edu with details)


This assignment is due in Lecture on Tuesday, 10.05.
It may ONLY be submitted in Lecture, in NH1006 at 2pm on Tuesday.
You must come IN PERSON to turn it in during your assigned Lecture section.

Late Policy: No email submission allowed—and don't "slip it under my door". If you need to make it up, you must do so during office hours, or make an appointment to see me, and you must request this appointment within 48 hours of when the assignment was originally due.

Personal Day/Sick Day policy: Everyone is permitted one "personal day/sick day" when you get to make up a missed homework assignment for free during office hours or via appointment. After that, you may not make up the homework assignment—you can only earn back the points through extra credit opportunities.

(For more details, see the syllabus and the homework policy)


Reading: Read Chapter 2, pages 45-61 (Sections 2.1 through 2.5) Then, answer the following questions. Be sure to check both sides.

  1. (3 pts) What is the definition of pi?




  2. (3 pts) According to what is known to mathematicians today, can the exact value of pi ever be represented with a finite number of digits?




     

  3. (5 pts) This chapter describes three ways of computing approximations of pi—the first of which is described in Section 2.4. Try to understand the basic idea behind this approach to computing the circumference of a circle with a known radius—then, imagine you are trying to explain it to someone in plain english, say, your roomate or your grandmother.

    What is the basic idea of this technique? (Don't get lost in the details—just focus on the big picture.)





Please turn over for more...

...continued from other side

  1. (4 pts) Section 2.5.2 describes a different approach—one based on a formula that "goes on forever". We approximate pi by summing up just a finite number of terms of this formula—knowing that the terms we "left out" are going to result in some small amount of inaccuracy.

    If you add together the first four terms of the Leibniz formula from p. 56, what is the resulting sum?










  1. Listing 2.2 on page 52 contains a function definition.

    1. (3 pts) What is the name of the function being defined?



    2. (3 pts) What is the name of the parameter of the function being defined?



    3. (3 pts) What is the value that is returned by the function being defined?







  2. (4 pts) What is the purpose of typing import math at the top of a Python file, or as the first command in a session in Python?






  1. (4 pts) If you have assigned a floating point value to the variable x, what do you type at the Python prompt to display the square root of x?






  2. (4 pts) In the code in Listing 2.3 on p. 58 of the textbook, there is a line acc = 0.0
    Obviously, this line assigned the variable acc to the value zero (as a floating point number).
    What I want you to tell me is why? In the context of this program, why are we setting acc to zero?






  3. (4 pts) (Continued from the previous problem). We set acc to zero at the start of listing 2.3.

    At the end of the function, we see the statement return acc.

    Will the value of acc still be zero at that point? If not, explain what value acc will have. (You'll need to read the text around the listing to learn this.)







End of H03