**CS 111 f19 - Homework 1** *Due: Wednesday, September 25, at 6:30pm* --- Python can be an incredible tool for mathematical or scientific work. This homework asks you to translate a variety of mathematical formulas into code and will help you practice using variables, arithmetic operations, print, and Python's math module. You should download [hw1.py](hw1.py) and insert your solutions to the exercises below into the indicated portions of the script. print statements in your solutions should include text that clearly indicates the meaning and units of any numbers being printed. Track how much time you spend on this homework outside class. You’re required to include this in [what you turn in](#whattoturnin). Post questions on the [Homework 1 forum](https://moodle.carleton.edu/mod/forum/view.php?id=479170)! # Lightning Strike Write a program that computes and prints out the distance to a lightning strike based on the time elapsed between the flash and the sound of thunder. Use the provided time_to_thunder variable in your calculation. The speed of sound is approximately 1100 ft/sec and 1 mile is 5280 ft. # Molecular Weight Write a program that computes and prints out the molecular weight of a carbohydrate based on the number of hydrogen, carbon, and oxygen atoms. You should use the following weights: Atom | Weight (grams / mole) ---- | --------------------- H | 1.0079 C | 12.011 O | 15.9994 Use the provided num_h_atoms, num_c_atoms, and num_o_atoms variables in your calculation. The result should be rounded to three decimal places. # Distance Between Two Points Write a program that computes and prints out the distance between two 2D points. Use the provided x1, y1, x2, and y2 variables in your calculation. \begin{equation*} distance = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} \end{equation*} # Area of a Triangle Write a program that computes and prints the area of a triangle given the length of its three sides $a$, $b$, and $c$ using the formulas below. Use the provided a, b, and c variables in your calculation. \begin{equation*} s = \frac{a + b + c}{2} \end{equation*} \begin{equation*} area = \sqrt{s(s - a)(s - b)(s - c)} \end{equation*} # Leaf-Cleaning Ladder Leaves are already starting to fall and soon falling leaves will inundate campus. To clear leaves out of hard-to-reach places, facilities will need ladders. Write a program to compute and print the length of a ladder required to reach a given height when leaned against a building. The provided height and angle variables indicate the height of those pesky leaves and the angle at which the ladder will lean. To compute length of the ladder use \begin{equation*} length = \frac{height}{\mathrm{sin}\: angle} \end{equation*} Note: the Python sin function requires the angle to be in radians. Use this formula to convert from degrees to radians: \begin{equation*} radians = \frac{\pi}{180}degrees \end{equation*} # Date of Easter A formula for computing the Gregorian date of [Easter](https://en.wikipedia.org/wiki/Easter) in the years 1982-2048, inclusive, is as follows. \begin{align*} a & = year\%19 \\ b & = year\%4 \\ c & = year\%7 \\ d & = (19a+24)\%30 \\ e & = (2b+4c+6d+5)\%7 \end{align*} The date of Easter is March 22 + d + e (which could be in April). Use these formulas to write a program that computes and prints the date of Easter in 2020. Assume the date will be in April (we will see how to avoid assumptions like this and make program behavior take different paths based on different circumstances at the end of week 2/beginning of week 3). # Advice Use a text editor such as Atom or Brackets to edit hw1.py. To run hw1.py, open a Terminal, navigate to the directory where it is saved, and enter the command python3 hw1.py. If you get stuck with an error, reading Think Python's [Debugging chapter](http://www.greenteapress.com/thinkpython2/html/thinkpython2021.html) might be helpful. You can also send me an email, or better yet post on the [homework 1 forums](https://moodle.carleton.edu/mod/forum/view.php?id=479170). Just be sure not to post significant pieces of your code, as that would violate academic honesty. Remember that to use something from Python's math module, include import math at the top of your script. You would then write math.sin(x) to compute the $sin$ of a variable x. It will likely be helpful to refer to the [documentation](https://docs.python.org/3/library/math.html) for the math module. [Think Python, section 3.2](http://www.greenteapress.com/thinkpython2/html/thinkpython2004.html#sec28) demonstrates using the math module. You may also find Python's built-in [round function](https://docs.python.org/3/library/functions.html#round) to be useful. To check your work, you might do these calculations by hand and compare what you got to what your program outputs. # What to Turn In Submit the following files via the [Moodle homework 1 page](https://moodle.carleton.edu/grade/report/grader/index.php?id=30479) - A file called hw1.py with your solutions to all six exercises. At the top of this file (and every file you submit) should be comments with your name, the date, and the purpose of the file (i.e., *CS 111 homework 1*). When this script is run, the answers to all six exercises should be printed out and clearly labeled. - A file called feedback.txt with the following information (you get points for answering these questions!): - How many hours you spent outside of class on this homework. - The difficulty of this homework for this point in a 100-level course as: too easy, easy, moderate, challenging, or too hard. - What did you learn on this homework (very briefly)? Rate the educational value relative to the time invested from 1 (low) to 5 (high).