<jupyter_start><jupyter_text>ENGR 1330-2022-1 Exam2-Laboratory Portion  **LAST NAME, FIRST NAME****R00000000**ENGR 1330 Exam 2 - Laboratory/Programming Skills---**Download** (right-click, save target as ...) this page as a jupyterlab notebook from: [s22-ex2-deploy.ipynb](http://54.243.252.9/engr-1330-webroot/5-ExamProblems/Exam2/Exam2/spring2022/s22-ex2-deploy.ipynb)**If you are unable to download the file, create an empty notebook and copy paste the problems into Markdown cells and Code cells (problem-by-problem)** --- Problem 0 (5 pts) : *Profile your computer*Execute the code cell below exactly as written.  If you get an error just continue to the remaining problems.<jupyter_code># Preamble script block to identify host, user, and kernel
import sys
! hostname
! whoami
print(sys.executable)
print(sys.version)
print(sys.version_info)<jupyter_output>DESKTOP-4NI7OSD
desktop-4ni7osd\jowhi
C:\Users\jowhi\anaconda3\python.exe
3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)<jupyter_text>--- Problem 1 NUMPY (10 points) :  *Show me the money!* Assume that you have access to 900,000 bank accounts belonging to other people. All of these account balances start with \\$101.23 USD in them. The interest rate for all the accounts is 5%, compounded daily. [Daily compounding](https://www.eduworks.com/Documents/Workshops/EdMedia1998/class/compound.htm) generally means that the stated annual rate is applied daily (also: [Daily compounding](https://www.cuemath.com/daily-compound-interest-formula/)) $\frac{5\%}{365}=0.01369\%$ per day. The interest is added to the balance of each account, with the exception of the fractions of cents (anything past the third decimal place) that are truncated (dropped). Let's pretend we are online robbers and we want to write some code to skim the excesss interest and place it into our own account. We are going to illegally skim the fractions that get truncated (dropped) out of the other people's accounts evertime their interest is calculated, and add the truncated amounts into our own account. Our account will begin with $0 but grow by the day.Execute the code block below to create the accounts<jupyter_code>import numpy as np
# create the accounts
accounts = np.array([101.23 for i in range(900000)])<jupyter_output><empty_output><jupyter_text>The daily interest is simply the product of the daily compounding rate and the account value$ P_{n+1} = P_{n} + i*P_{n}$  in this problem the result $i*P_{n}$ is only reported to the penny, any smaller part of the value is skimmed into the illegal bitcoin account.A function that performs the computations is shown below<jupyter_code># execute this code block to prototype the function
def add_interest(current_value,daily_rate):
    compounding_amount = current_value*daily_rate      # compute compounding amount.
    whole_dollar_ammount = current_value*daily_rate//1 # compute compounding amount whole dollar portion
    fractional_dollar_amount = compounding_amount - whole_dollar_ammount # compute compounding amount fractional dollar portion
    pennies = fractional_dollar_amount*100//1  # compute portion of fraction that are pennies
    skim = fractional_dollar_amount - pennies/100 
    output=(whole_dollar_ammount+pennies/100,skim) # return a tuple of interest to add, and amount to skim
    return(output)<jupyter_output><empty_output><jupyter_text>Implement the steps necessary to increase each of the 900,000 accounts by (5/365)% per day, truncate the accounts to the nearest penny, and add the truncated amount into a seperate account titled “bitcoin”    Using a repetition structure determine the abount in the bitcoin account after 1 day, 10 days and 100 days of stealing.<jupyter_code># complete the script in this block, supply indicated code to compute the steal
# generate the bitcoin account
bitcoin = 0
days = 0
# compute daily addition to each account, sweep fractional portion into bitcoin
while(1):
    if(bitcoin>=1000000): break
    if(days==1): print(f'Dollars (1st day): {bitcoin}')
    elif(days==10): print(f'Dollars (10th day): {bitcoin}')
    elif(days==100): print(f'Dollars (100th day): {bitcoin}')
    
    interest = add_interest(accounts, 0.01369/100)
    accounts = (accounts + interest[0])
    bitcoin = (bitcoin + np.sum(interest[1]))
    days +=1
print(f'\nFinal Amount: {bitcoin} after {days} days.')
# report bitcoin amount and days since steal begin<jupyter_output>Dollars (1st day): 3472.548300000006
Dollars (10th day): 34780.92750000005
Dollars (100th day): 353353.72500000324

Final Amount: 1001370.1500000241 after 275 days.<jupyter_text>Problem 2 (5 pts) : *Get the data files*<jupyter_code>######### CODE TO AUTOMATICALLY DOWNLOAD THE DATABASE ################
import requests # import needed modules to interact with the internet
# make the connection to the remote file (actually its implementing "bash curl -O http://fqdn/path ...")
remote_url = 'http://192.168.127.12/engr-1330-webroot/8-Labs/Lab15/galton_subset.csv' # a csv file
response = requests.get(remote_url) # Gets the file contents puts into an object
output = open('galton_subset.csv', 'wb') # Prepare a destination, local
output.write(response.content) # write contents of object to named local file
output.close() # close the connection<jupyter_output><empty_output><jupyter_text>--- Problem 3: Dataframe read/organize (10 pts): *read file into a dataframe, rename columns, show a few rows of the dataframe*Read the `galton_subset.csv` into a dataframe.  Name/rename the columns to **"Father","Mother","Child"**.  Display the first 9 rows of the dataframe.<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('galton_subset.csv')
df = df.rename(columns={'father':'Father', 'mother':'Mother', 'son':'Child'})
print(df.head(9))<jupyter_output>Father  Mother  Child
0    78.5    67.0   73.2
1    75.5    66.5   73.5
2    75.0    64.0   71.0
3    75.0    64.0   70.5
4    75.0    58.5   72.0
5    74.0    68.0   76.5
6    74.0    62.0   74.0
7    73.0    67.0   71.0
8    73.0    67.0   68.0<jupyter_text>--- Problem 4 Dataframe analyze/summarize (10 pts): *find mean values, father, mother, child*Using the dataframe from the previous problem, find the average height of **"Father","Mother","Child"** columns (series) and the standard deviation of these columns.On average which category is taller (father, mother, child)?<jupyter_code>avg_father = df['Father'].mean()
avg_mother = df['Mother'].mean()
avg_child = df['Child'].mean()

sd_father = df['Father'].std()
sd_mother = df['Mother'].std()
sd_child = df['Child'].std()

print(f'\nAverage Height Father: {avg_father}')
print(f'Standard Height: {sd_father}')

print(f'\nAverage Height Mother: {avg_mother}')
print(f'Standard Height: {sd_mother}')

print(f'\nAverage Height Child: {avg_child}')
print(f'Standard Height: {sd_child}')
# who is taller?
print('\nChild is Tallest')<jupyter_output>Child is Tallest<jupyter_text>--- Problem 5 Dataframe Histograms (10 points) :  *histograms; df['...'].hist(alpha=0.5,color='...')* Using the dataframe from the Problem 4, produce a histogram of fathers and a histogram of mothers on the same plot.  Do the histograms suggest that one group is shorter than the other?<jupyter_code>df['Father'].hist(alpha=0.5,color='red')
df['Mother'].hist(alpha=0.5,color='blue')
plt.legend(["Father","Mother"])
plt.ylabel('Count')
plt.xlabel('Height')
plt.show
# who is shorter?
print("Mother appears to be shorter on average")<jupyter_output>Mother appears to be shorter on average
{'fraction_non_alphanumeric': 0.1105117747664781, 'fraction_numerical': 0.0511774766478095, 'mean_word_length': 4.943706020328381, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '212006', 'license': 'CC0-1.0', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2332, 'n_words': 843, 'path': 'Playground/.ipynb_checkpoints/s22-ex2-deploy(1)-checkpoint.ipynb', 'repo_name': 'dustykat/engr-1330-psuedo-course', 'size': '7599'}