# <ins>Lab #2: Basics + Loops, Conditionals & Functions </ins>

These exercises are meant to give you some practice with the concepts from Tutorials 2.1-2.3, as well as Tutorials 1.1/1.2 since we didn't get to the exercises last week. Be sure to use best practices, comment your code, and be mindful of your units.


```python
# Import any libraries here:

```

***
## Arithmetic & variables

1. Use the quadratic equation, to find the roots of $5x^2 + 3x - 1$ by calculating the numerator and denominator separately. Round to 2 decimal places. (**Tip:** When parintheses in a big equation get a little hard to read, breaking it up like this is a good way to make code easier to read.)

$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$


```python
# Your code here:

```

2. Use the distance modulus, to find the distance to a star with apparent magnitude $m_v = 0.5$ and absolute magnitude $M_v = -5.85$.

$$m_v - M_v = 5log(d/10 \text{ pc})$$


```python
# Your code here:

```

***
## User input

Prompt the user for their age and calculate the percent of their life they've completed assuming they live to 80 years old.


```python
# Your code here:

```

***
## Indexing

1. Print the strings "pneumono," "ultra," "volcano," and "coniosis" by slicing the word "pneumonoultramicroscopicsilicovolcanoconiosis".


```python
# Your code here:

```

2. Print the 4th, 9th, and 15th letter and the letter at the 20th, 3rd, and 12th indices of the word from part one by indexing.


```python
# Your code here:

```

***
## `numpy` arrays

Use the Wein displacement law to calculate the temperatures of blackbodies with 20 peak wavelengths between 300nm and 700nm using arrays.

\begin{equation}
    \lambda_{peak}T = 0.29 \text{ cm K}
\end{equation}


```python
# Your code here:

```

***
## Conditional statements

Write a program that has the user input a wavelength or frequency and returns (a) the photon energy, and (b) the part of the electromagnetic spectrum in which a photon of that energy falls.

$$E = h\nu \quad\text{&}\quad \lambda\nu = c$$


```python
# Your code here:

```

***
## Loops and plotting

1. Add together every third number in the list [155,2,54,34,5,16,7,38,26,10] and print the result.


```python
# Your code here:

```

2. Plot the sine and cosine functions on [-2$\pi$,2$\pi$].


```python
# Your code here:

```

3. The rules for Pin-Pon are as follows:

    - Start counting numbers, starting from 1. 
    - Whenever the next number's a multiple of 3 (3, 6, 9,…), replace the actual number with, "Pin." 
    - Whenever the next number's a multiple of 5, replace it with the word, "Pon."
    - Whenever the number's a multiple of both 3 and 5, say, "Pin Pon."
    - Keep going until someone messes up.

Write a program that prints the results of the game for 1 through 100.


```python
# Your code here: 

```

***
## Putting it all together

These are meant to use all of your new skills at once. That being said, you may have notice that there's no "Functions" section above --- once you've completed each of the tasks below, please turn them into functions, comment them well

1. (From Lab 1): While DMS (degrees, minutes, seconds) and HMS (hours, minutes, seconds) formats for celestial coordinates have their place (e.g. in every database ever), having them in decimal degrees is often more convenient for calculations. Write two scripts: one that allows the user to enter in a DMS coordinate and prints it in decimal degrees, and another for HMS coordinates.


```python
# Your code here:

```

2. In my research on X-ray binaries, I utilize the Novikov-Thorne thin accretion disk approximation for black holes, which relates the temperature of the accertion disk to the mass of the accretor. Typical disk temperatures range between 0.5 and 1.0 keV. Using this relationship, calculate the mass of black holes (a) within this range, (b) in the "interesting" regime of 1.0 to 3.0 keV, and (c) in the "crazy" range of >5.0 keV. Plot your results, making sure the three regimes are clearly labeled in your plot.

$$T_{eff} \sim \Bigg(\frac{10M_\odot}{M}\Bigg)^{1/4} \text{ keV}$$


```python
# Your code here:

```

1b1019a87bb8cb70da47ea20d3b5fac9854be058
ipynb
Jupyter Notebook
files/astr211_lab2-exercises.ipynb
mvtea/mvtea.github.io
91cb2558e570bba35e2f0718c4c658cd7317bd5d
MIT
files/astr211_lab2-exercises.ipynb
mvtea/mvtea.github.io
91cb2558e570bba35e2f0718c4c658cd7317bd5d
MIT
files/astr211_lab2-exercises.ipynb
mvtea/mvtea.github.io
91cb2558e570bba35e2f0718c4c658cd7317bd5d
MIT
Qwen/Qwen-72B
1. YES
2. YES