Survey

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
```Computer Science 111
Artithmetic exercises
Type your answers to the following questions in a text file (not a Word file) and send it to me via
email. A transcript from IDLE (using Save As. . . from the File menu) is fine, but please edit out
anything extraneous using a text editor like TextEdit or TextWrangler.
Use the Python interpreter to answer the following questions. Where appropriate, provide both the
answer and the Python expression you used to get it.
1. The Library of Congress stores its holdings on 838 miles of shelves. Assuming an average
book is one inch thick, how many books would this hold?
2. If I gave you a nickel and promised to double the amount you have every hour for the next
24, how much money would you have at the end of this day? What if I only increased the
amount by 50% each hour, how much would you have? Use exponentiation to compute these
quantities.
3. The Library of Congress stores its holdings on 838 miles of shelves. How many round trips is
this between Granville and Columbus?
4. The earth is estimated to be 4.54 billion years old. The oldest known fossils of anatomically
modern humans are about 200,000 years old. What fraction of the earth’s life have humans
been around? Use Python’s scientific notation to compute this.
5. If you counted at an average pace of one number per second, how long would it take you to
count to 4.54 billion? Use Python’s scientific notation to compute this.
6. Suppose the internal clock in a modern computer can “count” about 2.8 billion ticks per
second. How long would it take such a computer to tick 4.54 billion times?
7. A hard drive in a computer can hold about a terabyte (240 bytes) of information. An average
song requires about 8 megabytes (8 × 220 bytes). How many songs can the hard drive hold?
8. What is the value of each of the following Python expressions? Make sure you understand
why in each case.
(a) 15 * 3 - 2
(b) 15 - 3 * 2
(c) 15 * 3 / 2
(d) 15 * 3.0 / 2
(e) 15 * 3 / 2.0
(f) 15 * 3 / 2e0
9. Every cell in the human body contains about 6 billion base pairs of DNA (3 billion in each set
of 23 chromosomes). The distance between each base pair is about 3.4 angstroms (3.4 × 10−10
meters). Uncoiled and stretched, how long is the DNA in a single human cell? There are
about 50 trillion cells in the human body. If you stretched out all of the DNA in the human
body end to end, how long would it be? How many round trips to the sun is this? The
distance to the sun is about 149,598,000 kilometers. Write Python statements to compute
the answer to each of these three questions. Assign variables to hold each of the values so
that you can reuse them to answer subsequent questions.
10. Set a variable named radius to have the value 10. Using the formula for the volume of a
sphere (V = (4/3)πr3 ), assign to a new variable named volume the volume of a sphere with
11. Now change the value of radius to 15. What is the value of volume now?
12. Suppose I wanted to swap the values of two variables named x and y. Why doesn’t the
following work? Show a method that does work.
x = y
y = x
13. What are the values of x and y at the end of the following? Make sure you understand why
this is the case.
x = 12.0
y = 2 * x
x = 6
14. What is the value of x at the end of the following? Make sure you understand why this is
the case.
x
x
x
x
=
=
=
=
0
x + 1
x + 1
x + 1
15. What are the values of x and y at the end of the following? Make sure you understand why
this is the case.
x = 12.0
y = 6
y = y * x
```
Related documents