The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Hi, can anybody do this homework? please show step by step, thank you
Â
Â
CS110 Project 2 (Straight-line Programs) Swami Iyer Problem 1. (Wind Chill ) Given the temperature t (in Fahrenheit) and the wind speed v (in miles per hour), the National
Weather Service defines the effective temperature (the wind chill) to be
w = 35.74 + 0.6215t + (0.4275t − 35.75)v 0.16 .
Write a program wind_chill.py that takes two floats t and v as command-line arguments and writes the wind chill.
$ python wind_chill . py 32 15
21.5889888905 Problem 2. (Body Mass Index ) The body mass index (BMI) is the ratio of the weight of a person (in kilograms) to the square
of the height (in meters). Write a program bmi.py that takes two floats w (for weight) and h (for height) as command-line
arguments and writes the BMI.
$ python bmi . py 75 1.83
22.3954134193 Problem 3. (Polar Coordinates) Write a program polar.py that takes two floats x and y representing p
the Cartesian
x2 + y 2 and
coordinates of a point as command-line arguments and writes the corresponding polar coordinates r =
θ = arctan(y/x).
$ python polar . py 1 1
1.41421356237
0.78 53981633 97 Problem 4. (Order Check ) Write a program order_check.py that takes three floats x, y, and z as command-line arguments
and writes True if the values are strictly ascending or descending (ie, x < y < z or x > y > z), and False otherwise.
$ python
True
$ python
False
$ python
True
$ python
False order_check . py 2 4 5
order_check . py 2 7 6
order_check . py 7 3 1
order_check . py 7 3 4 Problem 5. (Day of the Week ) Write a program day_of_week.py that takes three integers m (for month), d (for day), and y
(for year) as command-line arguments and writes the day of the week (0 for Sunday, 1 for Monday, and so on) D, calculated
as follows:
y0 = y − (14 − m)/12 x0 = y0 + y0 /4 − y0 /100 + y0 /400 m0 = m + 12 × ((14 − m)/12) − 2 D = (d + x0 + 31 × m0 /12) mod 7 $ python day_of_week . py 3 14 1879
5 Problem 6. (Mercator Projection) The Mercator projection is a conformal (angle preserving) projection that maps latitude
ϕ and longitude λ to rectangular coordinates (x, y). It is widely used — for example, in nautical charts and in the maps that
you print from the web. The projection is defined by the equations x = λ − λ0 and y = ln((1 + sin ϕ)/(1 − sin ϕ))/2, where
λ0 is the longitude of the point in the center of the map. Write a program mercator.py that takes three floats λ0 , ϕ, and λ as
command-line arguments and writes its projection, ie, the x and y values, separated by a space. Note that the equations use
degrees, whereas Python’s trigonometric functions use radians. Use math.radians() to convert degrees to radians. Use your
program to compute the Mercator projection of Boston (42.36â—¦ N and 71.06â—¦ W) with the center of the map being the prime
meridian (0â—¦ ).
1 of 3 CS110 Project 2 (Straight-line Programs) Swami Iyer $ python mercator . py 0 42.36 -71.06
-71.06 0.81764 6151942 Problem 7. (Great Circle) Write a program great_circle.py that takes four floats x1 , y1 , x2 , and y2 representing the latitude
and longitude in degrees of two points on earth as command-line arguments and writes the great-circle distance (in km)
between them, given by the equation:
d = 111 arccos(sin(x1 ) sin(x2 ) + cos(x1 ) cos(x2 ) cos(y1 − y2 )).
Note that this equation uses degrees, whereas Python’s trigonometric functions use radians. Use math.radians() and
to convert between the two. Use your program to compute the great-circle distance between Paris (48.87â—¦ N
â—¦
and 2.33 W) and San Francisco (37.8â—¦ N and 122.4â—¦ W).
math.degrees() $ python great_circle . py 48.87 -2.33 37.8 -122.4
8701.38954324 Problem 8. (Three Sort) Write a program three_sort.py that takes three integers as command-line arguments and writes
them in ascending order, separated by spaces. Use min() and max().
$
1
$
1
$
1
$
1
$
1
$
1 python
2 3
python
2 3
python
2 3
python
2 3
python
2 3
python
2 3 three_sort . py 1 2 3
three_sort . py 1 3 2
three_sort . py 2 1 3
three_sort . py 2 3 1
three_sort . py 3 1 2
three_sort . py 3 2 1 Problem 9. (Random Integer ) Write a program random_int.py that takes two integers a and b from the command line and
writes a random integer between a (inclusive) and b (exclusive).
$ python random_int . py 10 20
13 Problem 10. (Three Dice) Write a program three_dice.py that writes the sum of three random integers between 1 and 6,
such as you might get when rolling three dice.
$ python three_dice . py
5 Files to Submit
1. wind_chill.py
2. bmi.py
3. polar.py
4. order_check.py
5. day_of_week.py
6. mercator.py
7. great_circle.py
8. three_sort.py
2 of 3 CS110 Project 2 (Straight-line Programs) Swami Iyer 9. random_int.py
10. three_dice.py
11. report.txt Before you submit:
• Make sure your programs meet the input and output specifications by running the following command on the
terminal:
$ python run_tests . py [ < problems >] where the optional argument <problems> lists the numbers of the problems you want to test; all the problems are
tested if no argument is given.
• Make sure your programs meet the style requirements by running the following command on the terminal:
$ pep8 < program > where <program> is the .py file whose style you want to check.
• Make sure your report doesn’t exceed 400 lines, doesn’t contain spelling mistakes, and doesn’t contain lines that
exceed 80 characters. 3 of 3
Â
Attachments: