CS8, 10F, H01, due Thu Lecture 09.30—Miller/Ranum Ch1 (thru p. 28)—Total points: ?

Available online as http://www.cs.ucsb.edu/~pconrad/cs8/10F/homework/H01—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 Thursday, 09.30.
It may ONLY be submitted in Lecture, in NH1006 at 2pm on Thursday.
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)

Please note the following typo on p. 13:

"What if you want to divide 7 by 2 and get 7.5 as the answer?"

Should be:

"What if you want to divide 15 by 2 and get 7.5 as the answer?"

Reading: Read the syllabus for the course, and then read Chapter 1, at least up through page 28. Then, answer the following questions. Be sure to check both sides.

  1. Review pages 10-17, then answer these questions: at the Python prompt:
    1. (2 pts) What can you type to compute 100 divided by 11, and get back an exact result (i.e. a result with decimals?)

    2. (2 pts) If you type that, what answer do you get back? (Write the entire answer---all the decimal places)

    3. (2 pts) What can you type to divide 100 by 11, and throw away any remainder?

    4. (2 pts) What do you get if you type the expression from question c at the Python prompt?

  2. Read Section 1.5.1 (p. 10-13). Part of this section described how the Python interpreter works with input typed in at the Python prompt. According to the authors, the Python interpreter works in a loop—a series of steps repeated over and over again.

    As explained in the textbook: what are the three steps in the Python interpreter loop, and what happens at each of these three steps?
    1. (2 pts) Step 1:

    2. (2 pts) Step 2:

    3. (2 pts) Step 3:

Please turn over for more...

...continued from other side

  1. Section 1.5.1 also describes Python expressions as being made up of operators and operands. The book explains what operators are, but only implies what operands are—so here's a more clear explanation:

    • In an expression such as (3+5), there is one operator (+), and two operands: 3 and 5.
      • 3 is the left operand, and 5 is the right operand.
    • In an expression such as (3 + 5 * 2), there are two operators, + and *, but there are actually four operands, not three!
      • The operands of the * operator, which is applied first, are 5 and 2
      • The operands of the + operator, which is applied second, are 3 and the result of 5*2 (i.e. 10).

    So, read pages 10-13, and then answer these questions about the expression (2 * 8 + 3)

    1. (2 pts) What is the right operand of the * operator in this expression?

    2. (2 pts) What is the left operand of the + operator?

    3. (2 pts) What is the value of the following expression—i.e. what does it evaluate to—i.e. what is the final result, after the operations are carried out?

  2. Section 1.5.2 (p. 17-22) discusses a type of Python statement that can be used to give an object a name, and creates a variable.

    1. (2 pts) What is that type of statement called?

    2. (2 pts) Give an example of such a statement that creates a variable that has the integer value 195 and the name weight.

  1. Read pages 23-28 about using the cTurtle module. You may like to try the statements from the book as you read about them—you'll learn more, and have more fun if you do.

    In CSIL, this works: no problem. Note that if you want to USE the cTurtle module in Python on your own PC or Mac, there are some special things you have to do.

    Those are described at this link: http://www.cs.ucsb.edu/~pconrad/cs8/topics/cTurtle

    Once you have Turtle graphics installed correctly, you should be able to type this at the Python prompt, and not get an error message:

    >>> import cTurtle

    Then, answer these questions

    1. (2 pts) What do you type to create a new Turtle named fred ?

    2. (2 pts) Once you have a turtle named fred, what do you type to cause fred to move forward 50 pixels?

    3. (2 pts) If fred's current heading is 0 degrees, what direction is he facing?

    4. (2 pts) What do you type at the Python prompt to determine fred's current heading?

    5. (2 pts) The book talks about something called a constructor. What is a constructor?

    6. (2 pts) Which of the questions that you answered above involved a constructor?

    7. The book talks about something called parameters.

      (2 pts) Which of the answers to the questions above involves a parameter?

      (2 pts) What was that parameter?

End of H01