preamble goes here with instruction run the cell
student name block

## Take Home Part
<hr>

## Question 1:
- __When it is 8:00 in Lubbock,__
    - __It is 9:00 in New York__
    - __It is 14:00 in London__
    - __It is 15:00 in Cairo__
    - __It is 16:00 in Istanbul__
    - __It is 19:00 in Hyderabad__
    - __It is 22:00 in Tokyo__ <br>

__Write a function that reports the time in New York, London, Cairo, Istanbul, Hyderabad, and Tokyo based on the time in Lubbock. Use a 24-hour time format. Include error trapping that:__<br>

1- Issues a message like "Please Enter A Number from 00 to 23" if the first input is numeric but outside the range of [0,23].<br>
2- Takes any numeric input for "Lubbock time" selection , and forces it into an integer.<br>
3- Issues an appropriate message if the user's selection is non-numeric.<br>

__Check your function for these times:__
- 8:00
- 17:00
- 0:00


```python
#Suggested Solution:

def LBBtime():
    try:
        LBK = int(input('What hour is it in Lubbock?- Please enter a number from 0 to 23'))
        if LBK>23:
            print('Please Enter A Number from 00 to 23')
        if LBK<23 and LBK>=0:
            print("Time in New York is",LBK+1,":00")
            print("Time in London is",LBK+6,":00")
            print("Time in Cairo is",LBK+7,":00")
            print("Time in Istanbul is",LBK+8,":00")
            print("Time in Hyderabad is",LBK+11,":00")
            print("Time in Tokyo is",LBK+14,":00")
            return #null return
    except:
        print("Please Enter an Appropriate Input")
```


```python
LBBtime()
```

    Please Enter an Appropriate Input


<hr>

## Question 2: 
Follow the steps below. Add comments to your script and signify when each step and each task is done. *hint: For this problem you will need the numpy and pandas libraries.
- __STEP1: There are 8 digits in your R#. Define a 2x4 array with these 8 digits, name it "Rarray", and print it__
- __STEP2: Find the maximum value of the "Rarray" and its position__
- __STEP3: Sort the "Rarray" along the rows, store it in a new array named "Rarraysort", and print the new array out__
- __STEP4: Define and print a 4x4 array that has the "Rarray" as its two first rows, and "Rarraysort" as its next rows. Name this new array "DoubleRarray"__
- __STEP5: Slice and print a 4x3 array from the "DoubleRarray" that contains the last three columns of it. Name this new array "SliceRarray".__
- __STEP6: Define the "SliceRarray" as a panda dataframe:__
    - name it "Rdataframe",
    - name the rows as "Row A","Row B","Row C", and "Row D"
    - name the columns as "Column 1", "Column 2", and "Column 3"
- __STEP7: Print  the first few rows of the "Rdataframe".__
- __STEP8: Create a new dataframe object ("R2dataframe") by adding a column to the "Rdataframe", name it "Column X" and fill it with "None" values. Then, use the appropriate descriptor function and print the data model (data column count, names, data types) of the "R2dataframe"__
- __STEP9: Replace the **'None'** in the "R2dataframe" with 0. Then, print the summary statistics of each numeric column in the data frame.__
- __STEP10: Define a function based on the equation below, apply on the entire "R2dataframe", store the results in a new dataframe ("R3dataframe"), and print the results and the summary statistics again.__  
$$ y = x^2 - 5x +7 $$
- __STEP11: Print the number of occurrences of each unique value in "Column 3"__
- __STEP12: Sort the data frame with respect to "Column 1" with a descending order and print it__
- __STEP13: Write the final format of the "R3dataframe" on a CSV file, named "Rfile.csv"__
- __STEP14: Read the "Rfile.csv" and print its content.__<br>
** __Make sure to attach the "Rfile.csv" file to your midterm exam submission.__




```python
#Suggested Solution:

#Step0:
import numpy as np
import pandas as pd
#Step1:
Rarray = np.array([[1,6,7,4],[5,2,3,8]])     #Define Rarray
print(Rarray)
#Step2:
print(np.max(Rarray))          #Find the maximum Value
print(np.argmax(Rarray))       #Find the posirtion of the maximum value
#Step3:
Rarraysort = np.sort(Rarray,axis = 1) #Sort Rarray along the rows and define a new array
print(Rarraysort)          
#Step4:
DoubleRarray = np.array([[1,6,7,4],[5,2,3,8],[1,4,6,7],[2,3,5,8]])     #Define DoubleRarray
print(DoubleRarray)
#Step5:
SliceRarray = DoubleRarray[0:4,1:4]     #Slice DoubleRarray and Define SliceRarray
print(SliceRarray)
#Step6:
myrowname = ["Row A","Row B","Row C","Row D"]
mycolname = ["Column 1", "Column 2","Column 3"]
Rdataframe = pd.DataFrame(SliceRarray,myrowname,mycolname)     #Define Rdataframe
#Step7:
print(Rdataframe.head())     #Print the first few rows of the Rdataframe
#Step8:
Rdataframe['Column X']= None     #Add a new column, "Column X"
R2dataframe = Rdataframe         #Define R2dataframe
print(R2dataframe.info())               #Get the info
#Step9:
R2dataframe = R2dataframe.fillna(0)     #Replace NAs with 0
print(R2dataframe.describe())                 #Get the summary statistics
#Step10:
def myfunc(x):  # A user-built function
    y = (x**2) - (10*x) +7
    return(y)
R3dataframe = R2dataframe.apply(myfunc)     #Apply the function on the entire R2dataframe
print(R3dataframe)
print(R3dataframe.describe())
#Step11:
print(R3dataframe['Column 3'].value_counts())  #Returns the number of occurences of each unique value in Column 3
#Step12:
print(R3dataframe.sort_values('Column 1', ascending = False)) #Sorting based on Column 1
#Step13:
R3dataframe.to_csv('Rfile.csv')     #Write R3dataframe on a CSV file
#Step14:
readfilecsv = pd.read_csv('Rfile.csv') #Read the Rfile.csv
print(readfilecsv)         #Print the contents of the Rfile.csv
```

    [[1 6 7 4]
     [5 2 3 8]]
    8
    7
    [[1 4 6 7]
     [2 3 5 8]]
    [[1 6 7 4]
     [5 2 3 8]
     [1 4 6 7]
     [2 3 5 8]]
    [[6 7 4]
     [2 3 8]
     [4 6 7]
     [3 5 8]]
           Column 1  Column 2  Column 3
    Row A         6         7         4
    Row B         2         3         8
    Row C         4         6         7
    Row D         3         5         8
    <class 'pandas.core.frame.DataFrame'>
    Index: 4 entries, Row A to Row D
    Data columns (total 4 columns):
     #   Column    Non-Null Count  Dtype 
    ---  ------    --------------  ----- 
     0   Column 1  4 non-null      int64 
     1   Column 2  4 non-null      int64 
     2   Column 3  4 non-null      int64 
     3   Column X  0 non-null      object
    dtypes: int64(3), object(1)
    memory usage: 160.0+ bytes
    None
           Column 1  Column 2  Column 3  Column X
    count  4.000000  4.000000  4.000000       4.0
    mean   3.750000  5.250000  6.750000       0.0
    std    1.707825  1.707825  1.892969       0.0
    min    2.000000  3.000000  4.000000       0.0
    25%    2.750000  4.500000  6.250000       0.0
    50%    3.500000  5.500000  7.500000       0.0
    75%    4.500000  6.250000  8.000000       0.0
    max    6.000000  7.000000  8.000000       0.0
           Column 1  Column 2  Column 3  Column X
    Row A       -17       -14       -17         7
    Row B        -9       -14        -9         7
    Row C       -17       -17       -14         7
    Row D       -14       -18        -9         7
            Column 1   Column 2   Column 3  Column X
    count   4.000000   4.000000   4.000000       4.0
    mean  -14.250000 -15.750000 -12.250000       7.0
    std     3.774917   2.061553   3.947573       0.0
    min   -17.000000 -18.000000 -17.000000       7.0
    25%   -17.000000 -17.250000 -14.750000       7.0
    50%   -15.500000 -15.500000 -11.500000       7.0
    75%   -12.750000 -14.000000  -9.000000       7.0
    max    -9.000000 -14.000000  -9.000000       7.0
    -9     2
    -14    1
    -17    1
    Name: Column 3, dtype: int64
           Column 1  Column 2  Column 3  Column X
    Row B        -9       -14        -9         7
    Row D       -14       -18        -9         7
    Row A       -17       -14       -17         7
    Row C       -17       -17       -14         7
      Unnamed: 0  Column 1  Column 2  Column 3  Column X
    0      Row A       -17       -14       -17         7
    1      Row B        -9       -14        -9         7
    2      Row C       -17       -17       -14         7
    3      Row D       -14       -18        -9         7


<hr>

## Problem 3

Graphing Functions Special Functions 

Consider the two functions listed below:

\begin{equation}
f(x) = e^{-\alpha x}
\label{eqn:fofx}
\end{equation}

\begin{equation}
g(x) = \gamma sin(\beta  x)
\label{eqn:gofx}
\end{equation}

Prepare a plot of the two functions on the same graph. 

Use the values in Table below for $\alpha$, $\beta$, and $\gamma$.

|Parameter|Value|
|:---|---:|
|$\alpha$|0.50|
|$\beta$|3.00|
|$\gamma$|$\frac{\pi}{2}$|


The plot should have $x$ values ranging from $0$ to $10$ (inclusive) in sufficiently small increments to see curvature in the two functions as well as to identify the number and approximate locations of intersections. In this problem, intersections are locations in the $x-y$ plane where the two "curves" cross one another of the two plots.


```python
# By-hand evaluate f(x) for x=1, alpha = 1/2
```


```python
# By-hand evaluate g(x) for x=3.14, beta = 1/2, gamma = 2
```


```python
# Define the first function f(x,alpha), test the function using your by hand answer
def f(x,alpha):
    import math
    f = math.exp(-1.0*alpha*x)
    return f

f(1,0.5)
```




    0.6065306597126334




```python
# Define the second function g(x,beta,gamma), test the function using your by hand answer
def g(x,beta,gamma):
    import math
    f = gamma*math.sin(beta*x)
    return f

g(3.14,0.5,2.0)
```




    1.9999993658636692




```python
# Built a list for x that ranges from 0 to 10, inclusive, with adjustable step sizes for plotting later on
howMany = 10
scale = 10.0/howMany
xvector = []
for i in range(0,howMany+1):
    xvector.append(scale*i)
#xvector # activate to display
```


```python
# Build a plotting function that plots both functions on the same chart
alpha = 0.5
beta = 0.5
gamma = 2.0
yf = []
yg = []
for i in range(0,howMany+1):
    yf.append(f(xvector[i],alpha))
    yg.append(g(xvector[i],beta,gamma))

def plot2lines(list11,list21,list12,list22,strx,stry,strtitle): # plot list1 on x, list2 on y, xlabel, ylabel, title
    from matplotlib import pyplot as plt # import the plotting library from matplotlibplt.show()
    plt.plot( list11, list21, color ='green', marker ='s', linestyle ='dashdot' , label = "Observed" ) # create a line chart, years on x-axis, gdp on y-axis
    plt.plot( list12, list22, color ='red', marker ='o', linestyle ='solid' , label = "Model") # create a line chart, years on x-axis, gdp on y-axis
    plt.legend()
    plt.title(strtitle)# add a title
    plt.ylabel(stry)# add a label to the x and y-axes
    plt.xlabel(strx)
    plt.show() # display the plot
    return #null return

plot2lines(xvector,yf,xvector,yg,'x-value','y-value','plot of f and g')
```


```python
# Using the plot as a guide, find the values of x where the two curves intercept (i.e. f(x) = g(x))

xguess = float(input('my guess for x')) # ~0.7, and 6.25
alpha = 0.5
beta = 0.5
gamma = 2.0
result = f(xguess,alpha) - g(xguess,beta,gamma)
print('f(x) - g(x) =', result)
```

    my guess for x 6.25


    f(x) - g(x) = 0.010753149164711609


<hr>

## Bonus Problem 1. Extra Credit (You must complete the regular problems)!
__create a class to compute the average grade (out of 10) of the students based on their grades in Quiz1, Quiz2, the Mid-term, Quiz3, and the Final exam.__

| Student Name  |   Quiz 1   |   Quiz 2   |   Mid-term   |   Quiz 3   |  Final Exam  |
| ------------- | -----------| -----------| -------------| -----------| -------------|
| Harry         | 8          | 9          | 8            | 10         | 9            |
| Ron           | 7          | 8          | 8            | 7          | 9            |
| Hermione      | 10         | 10         | 9            | 10         | 10           |
| Draco         | 8          | 7          | 9            | 8          | 9            |
| Luna          | 9          | 8          | 7            | 6          | 5            |

1. __Use docstrings to describe the purpose of the class.__
2. __Create an object for each car brand and display the output as shown below.__

"Student Name": **Average Grade**  

3. __Create and print out a dictionary with the student names as keys and their average grades as data.__



```python
#Suggested Solution:

class Hogwarts:
    """This class calculates the average grade of the students"""
    def __init__(self, Name,Quiz1,Quiz2,MidTerm,Quiz3,Final):
        self.Name = Name
        self.Quiz1 = Quiz1
        self.Quiz2 = Quiz2
        self.MidTerm = MidTerm
        self.Quiz3 = Quiz3
        self.Final= Final
        
    def average(self):
        return (self.Quiz1 + self.Quiz2 + self.MidTerm + self.Quiz3 + self.Final) /5


S1 = Hogwarts('Harry',8,9,8,10,9)                      #Fill the instances
S2 = Hogwarts('Ron',7,8,8,7,9)
S3 = Hogwarts('Hermione',10,10,9,10,10)
S4 = Hogwarts('Draco',8,7,9,8,9)
S5 = Hogwarts('Luna',9,8,7,6,5)

print("Harry", S1.average())
print("Ron", S2.average())
print("Hermione", S3.average())
print("Draco", S4.average())
print("Luna", S5.average())

GradeDict = {"Harry":S1.average(),"Ron":S2.average(),"Hermione":S3.average(),"Draco":S4.average(),"Luna":S5.average()}
print(GradeDict)
```

    Harry 8.8
    Ron 7.8
    Hermione 9.8
    Draco 8.2
    Luna 7.0
    {'Harry': 8.8, 'Ron': 7.8, 'Hermione': 9.8, 'Draco': 8.2, 'Luna': 7.0}


<hr>

## Bonus 2 Extra credit (You must complete the regular problems)!
#### Write the VOLUME Function to compute the volume of Cylinders, Spheres, Cones, and Rectangular Boxes. This function should:
- First, ask the user about __the shape of the object__ of interest using this statement:<br>
*"Please choose the shape of the object. Enter 1 for "Cylinder", 2 for "Sphere", 3 for "Cone", or 4 for "Rectangular Box""*<br>
- Second, based on user's choice in the previous step, __ask for the right inputs__.
- Third, print out an statement with __the input values and the calculated volumes__.

#### Include error trapping that:

1. Issues a message that *"The object should be either a Cylinder, a Sphere, a Cone, or a Rectangular Box. Please Enter A Number from 1,2,3, and 4!"* if the first input is non-numeric.
2. Takes any numeric input for the initial selection , and force it into an integer.
4. Issues an appropriate message if the user's selection is numeric but outside the range of [1,4]
3. Takes any numeric input for the shape characteristics , and force it into a float.
4. Issues an appropriate message if the object characteristics are as non-numerics.

#### Test the script for:
1. __Sphere, r=10__
2. __r=10 , Sphere__
3. __Rectangular Box, w=5, h=10, l=0.5__


- <font color=orange>__Volume of a Cylinder = πr²h__</font>
- <font color=orange>__Volume of a Sphere = 4(πr3)/3__</font>
- <font color=orange>__Volume of a Cone = (πr²h)/3__</font>
- <font color=orange>__Volume of a Rectangular Box = whl__</font>


```python
#Suggested Solution:

import numpy as np # import NumPy: for large, multi-dimensional arrays and matrices, along with  high-level mathematical functions to operate on these arrays.
pi = np.pi #pi value from the np package

def VOLUME():
    try:
        UI = input('Please choose the shape of the object. Enter 1 for "Cylinder", 2 for "Sphere", 3 for "Cone", or 4 for "Rectangular Box"')
        UI =int(UI)
        if UI==1:
                try:
                    UI2 = input('Please enter the radius of the Cylinder')
                    r= float(UI2)
                    UI3 = input('Please enter the height of the Cylinder')
                    h= float(UI3)
                    V= pi*h*r**2
                    print("The volume of the Cylinder with the radius of ",r," and the height of ",h," is equal to", V)
                except:
                    print("The radius and height of the Cylinder must be numerics. Please Try Again!")
        elif UI==2:
                try:
                    UI2 = input('Please enter the radius of the Sphere')
                    r= float(UI2)
                    V= (4*pi*r**3)/3
                    print("The volume of the Sphere with the radius of ",r," is equal to", V)
                except:
                    print("The radius of the Sphere must be numeric. Please Try Again!")
        elif UI==3:
                try:
                    UI2 = input('Please enter the radius of the Cone')
                    r= float(UI2)
                    UI3 = input('Please enter the height of the Cone')
                    h= float(UI3)
                    V= (pi*h*r**2)/3
                    print("The volume of the Cone with the radius of ",r," and the height of ",h," is equal to", V)
                except:
                    print("The radius and height of the Cone must be numerics. Please Try Again!")
        elif UI==4:
                try:
                    UI2 = input('Please enter the width of the Rectangular Box')
                    w= float(UI2)
                    UI3 = input('Please enter the height of the Rectangular Box')
                    h= float(UI3)
                    UI4 = input('Please enter the length of the Rectangular Box')
                    l= float(UI4)
                    V= w*h*l
                    print("The volume of the Rectangular Box with the width of ",w," and the height of ",h," and the length of ",l," is equal to", V)
                except:
                    print("The width, height, and length of the Rectangular Box must be numerics. Please Try Again!")
        else:
            print("Please Enter A Number from 1,2,3, and 4!")

    except:
        print("The object should be either a Cylinder, a Sphere, a Cone, or a Rectangular Box. Please Enter A Number from 1,2,3, and 4!")




```


```python
VOLUME()
```

    Please choose the shape of the object. Enter 1 for "Cylinder", 2 for "Sphere", 3 for "Cone", or 4 for "Rectangular Box" 1
    Please enter the radius of the Cylinder 3
    Please enter the height of the Cylinder 3


    The volume of the Cylinder with the radius of  3.0  and the height of  3.0  is equal to 84.82300164692441



```python

```




```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

24da71b71e70487e0bdaaec92d8f0e4b17d7a22b
ipynb
Jupyter Notebook
5-ExamProblems/.src/EX1-F2020-Development/Exam1-TakeHome.ipynb
dustykat/engr-1330-psuedo-course
3e7e31a32a1896fcb1fd82b573daa5248e465a36
CC0-1.0
5-ExamProblems/.src/EX1-F2020-Development/Exam1-TakeHome.ipynb
dustykat/engr-1330-psuedo-course
3e7e31a32a1896fcb1fd82b573daa5248e465a36
CC0-1.0
5-ExamProblems/.src/EX1-F2020-Development/Exam1-TakeHome.ipynb
dustykat/engr-1330-psuedo-course
3e7e31a32a1896fcb1fd82b573daa5248e465a36
CC0-1.0
Qwen/Qwen-72B
1. YES
2. YES