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.10 for your work. 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 is the easiest way to install and manage Python. If you work locally, you may launch Jupyter Lab either from the Navigator application or via the command-line as jupyter lab.

Due Date

The assignment is due at 11:59pm on Friday, September 2.

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 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, Illinois (5 pts)

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

Hello,
Illinois

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 defines four variables, the gravitational constant (G), mass of first object (m1), mass of second object (m2), and distance between them (r). Initialize G, m1, m2, and r to \(6.67408 × 10^{-11}\), \(5.972 × 10^{24}\) (mass of the earth), \(7.342 × 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=2\), \(b=-5\), \(c=3\). Then, compute x using the quadratic formula. \[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \] Note that there will be two solutions due to the +/-. Print both of them. I should be able to change the values of a, b, and c and have the formula work. (If the root is repeated, it is ok to print it twice.)

Hints
  • Python has an exponentiation operator that works for roots as well…
  • What happens with \(a=1\), \(b=3\), \(c=4\). Does your code still work?