CSCI 1100 — Computer Science 1 Homework 1

This part is worth 30 points.
Before getting started, practice writing Python expressions and assignment statements using
the Python interpreter! If nothing else, repeat some of the problems we worked on during lecture
to see if you can solve them yourself…
For this part of the homework you are going to write one Python (.py) file that outputs the
results of several calculations. Your code should use variables, expressions, assignment statements
and print statements. You may write a function to make your code shorter, as discussed in Lecture 3,
but while it is desirable it is not necessary in order to earn full credit. To make your code easier to
read, your .py file should have blank lines separating the groups of calculations.
The distances (in miles) of the planets to the sun and the diameters of the five planets closest
to the sun are as follows:
Planet Diameter Distance
Mercury 3,032 35,983,610
Venus 7,531 67,232,360
Earth 7,926 92,957,100
Mars 4,222 141,635,300
Jupiter 88,846 483,632,000
Write Python code that outputs the name ‘Mercury’ and then outputs on each successive line
• its distance to the sun relative to the distance of the earth from the sun,
• its diameter relative to the earth’s diameter,
3
• the time, in minutes, that light takes to travel from the sun to Mercury (use 186,000 miles
per second as the speed of light), and
• Mercury’s volume relative to that of the earth.
When you run the program (in the Wing IDE) the output should look something like
Mercury
relative distance 0.387099102704
relative diameter 0.382538480949
light time (minutes) 3.22433781362
relative volume 0.0559790323342
Repeat the calculations for Venus, Mars and Jupiter, outputting a blank line after the output
for each planet. At this point, you can introduce a function if you wish to perform the calculations
for a single planet and then call this function once for each of the four planets.
The final output from your program should be the average distance of the five planets from the
sun and the average diameter of the planets. You may use integer arithmetic to complete these
calculations.
The complete output from your program should look very close to
Mercury
relative distance 0.387099102704
relative diameter 0.382538480949
light time (minutes) 3.22433781362
relative volume 0.0559790323342
Venus
relative distance 0.723262236021
relative diameter 0.950164017159
light time (minutes) 6.02440501792
relative volume 0.857477483265
Mars
relative distance 1.52366306608
relative diameter 0.532677264698
light time (minutes) 12.6913351254
relative volume 0.151144546868
Jupiter
relative distance 5.20274406151
relative diameter 11.209437295
light time (minutes) 43.3362007168
relative volume 1408.48243619
Average planetary distance in miles is 164288074
Average planetary diameter in miles is 22311
In order to complete Part 1 of the HW 1, please submit the file (e.g. part1.py) containing your
solution to the submission server. Be sure to submit for Part 1, which is the second submission line
on the website. Do not submit anything other than your single Python file!
4
Final note: You could write a Python program that simply prints the output provided above.
It would start with something like
print “Mercury”
print ” relative distance 0.387099102704″
print ” relative diameter 0.382538480949″
print ” light time (minutes) 3.22433781362″
print ” relative volume 0.0559790323342″
print “”
etc. If you do this, you will earn 0 points for the assignment. You must let Python do all of the
calculations. To illustrate, if we suddenly realized that we had mistyped Earth’s distance from the
sun, you should have to change only one line of your code and the rest of your program should
work correctly! The same is true of Part 2.
Part 2
This part is worth 30 points.
Before getting started, practice writing Python functions using the Python interpreter! If
nothing else, repeat some of the problems we worked on during lecture to see if you can solve them
yourself…
The (fictional) Acme computing and social networks company has large data centers distributed
throughout the world and these centers consume a large amount of energy each year. Environmental
organizations would like Acme to reduce its carbon footprint, and pay in “carbon credits” for the
pollution it produces.
• Each data center is formed by a sequence of standard shipping “containers”, each containing
1,160 servers, and each requiring about 250 kilowatts of energy. A common measurement of
energy usage is to multiple the kilowatts times a unit of time, typically an hour, yielding the
kilowatt-hour. As a sanity check to make this clear, these numbers imply that a container
uses 250 × 24 × 365 ≈ 2 million kilowatt-hours per year. To give a sense of the scale of this
number, an efficient refrigerator uses about 500 kilowatt-hours of energy per year.
• Each data center uses about 200 containers, and Acme has about 15 data centers.
• The unnamed environmental organization wants Acme to pay $12 per ton of carbon used,
and Acme consumes about 0.0006 tons of carbon per kilowatt-hour.
Using this information, write a Python program to calculate and output how much enery Acme
uses for the year 2012 and how much Acme must pay in carbon credits. Assuming Acme adds 4
containers to each center in each year and adds 2 data centers in 2013, 5 in 2014, and 3 in 2015,
how much must Acme pay in carbon credits each year?
The central part of your program is that you must write a function that takes the number of
centers that Acme has and the number of containers per center and calculates the amount of money
Acme must pay.
The output from your program should be
In 2012 Acme should pay $ 47304000.0
In 2013 Acme should pay $ 54683424.0
In 2014 Acme should pay $ 72154368.0
In 2015 Acme should pay $ 83570400.0

Powered by WordPress