Assignment 1

Goals

The goal of this assignment is to get acquainted with Python using Jupyter Notebooks.

Instructions

You will be doing your work in a Jupyter notebook for this assignment. You may choose to work on this assignment on a hosted environment (e.g. tiger) or on your own local installation of Jupyter and Python. You should use Python 3.12 for your work. (Older versions may work, but your code will be checked with Python 3.12.) To use tiger, use the credentials you received. If you work remotely, make sure to download the .ipynb file to turn in. If you choose to work locally, Anaconda or miniforge are probably the easiest ways to install and manage Python. If you work locally, you may launch Jupyter Lab either from the Navigator application (anaconda) or via the command-line as jupyter-lab or jupyter lab.

Due Date

The assignment is due at 11:59pm on Monday, January 29.

Submission

You should submit the completed notebook file required for this assignment on Blackboard. The filename of the notebook should be a1.ipynb.

Details

Please make sure to follow instructions to receive full credit. Use a markdown cell to Label each part of the assignment with a heading that includes the number of the section you are completing. You may put the code for each part into one or more cells.

0. Name & Z-ID (5 pts)

The first cell of your notebook should be a markdown cell with a line for your name and a line for your Z-ID. If you wish to add other information (the assignment name, a description of the assignment), you may do so after these two lines.

1. Hello, DeKalb (5 pts)

Write code that prints “Hello, DeKalb” but split into two lines like the following

Hello,
DeKalb

2. Hello, <name> (5 pts)

Write code that assigns your name (a string) to a variable, and then prints Hello, <name> where <name> comes from the variable. Thus, if you change the string assigned to the variable, the output should change.

3. Newton’s Law of Universal Gravitation (10 pts)

Write code that assigns four variables: the gravitational constant (G), mass of first object (m1), mass of second object (m2), and distance between them (r). Set G, m1, m2, and r to \(6.67408 × 10^{-11}\), \(5.972 × 10^{24}\) (mass of the earth), \(7.34767309 × 10^{22}\) (mass of the moon), and \(3.844 × 10^8\) (distance between earth and the moon), respectively. Using the initialized variables, compute the gravitational force (F) according to the equation below. \[ F = G\frac{m_1 m_2}{r^2} \] Without using a print statement, output the value of F, .

4. Quadratic Formula (10 pts)

Write code that defines three variables (a, b, and c) from the equation \(ax^2 + bx + c = 0\). Initialize these variables to \(a=1\), \(b=-5\), \(c=6\). Then, compute x using the quadratic formula. \[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \] Note that there will be usually be two solutions due to the +/-. Print both of them (when there is only one solution, duplicating it is ok). I should be able to change the values of a, b, and c and have the formula work. You do not need to write a function for this, just assign the variables as part of the code. Also, we will not test with a=0 but feel free to add logic to deal with this case.

Hints
  • Python has an exponentiation operator that works for roots as well… You do not need to use any libraries.
  • What happens with \(a=1\), \(b=3\), \(c=4\). Does your code still work? Do not assume you know what will happen!