Computer Science 1 Homework 1: Calculations and Strings

$30.00

Category:

Description

5/5 - (4 votes)

Part 1: Astronomical Calculations
Jupiter, the largest planet in our solar system, has a diameter of 88,846 miles and its average
distance from the Sun is about 483,632,000 miles. These are big numbers and as such they are a
bit hard to understand intuitively. One way to appreciate them is to compare them to the values
for Earth, which has a diameter of 7,926 miles and a distance from the Sun of about 92,957,100
miles. The size can also be compared to the Sun, which has an average diameter of about 864,938
miles. Use 186,000 miles per second as the speed of light.
Write a Python program to calculate and output
1. the ratio of the Sun’s radius to Jupiter’s,
2. the ratio of the Sun’s radius to Earth’s,
3. the ratio of Jupiter’s radius to Earth’s,
4. the ratio of Jupiter’s distance from the Sun to the Earth’s distance from the Sun,
5. the ratio of Jupiter’s volume to that of the Earth (assuming both are spheres),
6. the time in minutes it takes light to travel from the Sun to Earth (use 186, 000 miles per
second as the speed of light), and
7. the time in minutes it takes light to travel from the Sun to Jupiter.
Your output must match
Sun-to-Jupiter radius ratio:
Sun-to-Earth radius ratio:
Jupiter-to-Earth radius ratio:
Jupiter-to-Earth Sun distance ratio:
Sun-to-Jupiter volume ratio:
Sun-to-Earth volume ratio:
Jupiter-to-Earth volume ratio:
Sun to Earth light travel time in minutes:
Sun to Jupiter light travel time in minutes:
where in each case is replaced by the floating point value your program calculates. You
must use the value 3.14159 for π or your output will differ from ours. (We will see very soon how
to get more accurate values of π.)
Your program must have the five distances and diameter values typed into the code each exactly
once and then use variables after that. This would make it easy to change if, for example, we
decided to use the values for Saturn instead. It would be even better if a string variable stored the
name for Jupiter and then this name were used in the print statements.
Upload your Python program file to Submitty as Part 1 of HW 1.
Part 2: Speed Calculations
Many exercise apps record both the time and the distance a user covers while walking, running,
biking or swimming. Some users of the apps want to know their average pace in minutes and
seconds per mile, while others want to know their average speed in miles per hour. For example,
if I run 6.3 miles in 53 minutes and 30 seconds, my average pace is 8 minutes and 29 seconds per
mile and my average speed is 7.07 miles per hour.
Your job in Part 2 of this homework is to write a program that asks the user for the minutes,
seconds and miles from an exercise event and outputs both the average pace and the average speed.
Here is an example showing the expected output of your program:
Minutes ==> 53
Seconds ==> 30
Miles ==> 6.3
Pace is 8 minutes and 29 seconds per mile.
Speed is 7.065420560747664 miles per hour.
You can expect minutes and seconds to both be integers, but miles will be a float. The two outputs
for the Pace must both be integers, so please use integer division and remainder operations. Note
that if you have a float value then the function int gives you the integer value. For example
>>> x = 29.52
>>> y = int(x)
>>> print(y)
29
The output for the Speed will be a float. (Very soon we will learn methods for shortening the speed
output, but we will not do so for this assignment.) Notice that our solution generates the blank
line before the output of the calculations. When you have tested your code and are sure that it
works, please submit it as Part 2 of Homework 1.
Part 3: Madlibs
In this part you will write a Python program to construct the Madlib given below:
Hello ,
Good morning! Are you looking forward to a/an ?
You will a lot of and feel when you do.
If you do not, you will this .
Did you watch the this ?
Were you when the won?
Have a/an day!
You will ask the user of the program for the missing words — those enclosed in < > — using the
input function. You will then take all the user specified inputs, and construct the above Madlib.
(Be sure to reread the Input format for homeworks in this class discussion in the instructions above.)
Make sure your output looks like the above paragraph, except that the missing information is filled
in with the user input. Here is an example run of the program (how it will look at the homework
submission server):
Let’s play MadLibs for Homework 1
Type one word responses to the following:
proper_name ==> Alex
adjective ==> interesting
noun ==> semester
verb ==> write
noun ==> code
emotion ==> proud
verb ==> struggle
noun ==> semester
noun ==> Olympics
season ==> summer
emotion ==> excited
team-name ==> USA
adjective ==> nice
Here is your Mad Lib…
Hello Alex,
Good morning! Are you looking forward to a/an interesting semester?
You will write a lot of code and feel proud when you do.
If you do not, you will struggle this semester.
Did you watch the Olympics this summer?
Were you excited when the USA won?
Have a/an nice day!
We’ve provided reasonable inputs, but the idea of MadLibs is to input random words and see how
silly the result looks. Try it!
Of course, the program you write will only work for the specific MadLib we’ve written above. A
more challenging problem, which you will be capable of solving by the end of the semester, is to
write a program that reads in any MadLib, figures out what to ask the user, asks the user, reads
the input, and generates the final MadLib.
When you have tested your code and you are sure that it works, please submit it as the solution
to Part 3 of the homework.