CS8, 09M, UCSB
H01: (Based on Miller/Ranum, Chapter 1) Total points: ? (printable PDF)
Accepted: on paper, in lecture (11am-12:25pm, Phelps 1401) on Monday, August 10th
No email submission allowed.
Name: (3 pts)______________________________ UCSBNetID (3 pts) _____________________
Lab Section (2 pts) Circle one: Thu 11am Thu 12:30pm Unknown
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 there
- download Python 3.0 to your PC or Mac, and access Python 3.0 there
The way to access these systems will be explained in lecture and/or during lab on Thursday August 6
- Review pages 10-17, then answer these questions: at the Python prompt:
- (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 pts) If you type that, what answer do you get back? (Write the entire answer---all the decimal places)
- (2 pts) What can you type to divide 100 by 11, and throw away any remainder?
- (2 pts) What do you get if you type the expression from question c at the Python prompt?
- Read pages 17-23 about variables and the assignment statement, and then answer these questions:
- (2 pts) What is the assignment statement that would give the variable x the value of 100 divided by 11 (as a floating-pt number).
- (2 pts) Type that assignment statement into Python. Then type the value x * 11 at the Python prompt, which should multiply the value of x by 11. What value do you get back?
- (2 pts) On some computers the answer to the previous question is not surprising but on many computers (including the CSIL lab computers) you get back a suprising result. Were you surprised?
If you didn't get back the answer you expected, why do you think you got something different from that?
Please turn over for more problems
Continued from other side
- 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.
But note that if you want to USE the cTurtle module in Python, 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
- (4 pts) What do you type to create a new Turtle named
fred ?
- (4 pts) Once you have a turtle named fred, what do you type to cause fred to move forward 50 pixels?
- (4 pts) If fred's current heading is 0 degrees, what direction is he facing?
- (4 pts) What do you type at the Python prompt to determine fred's current heading?
- (4 pts) The book talks about something called a constructor. What is a constructor?
- (4 pts) Which of the questions that you answered above involved a constructor?
- 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