Skip to content

Commit b951f9d

Browse files
committed
first commit
0 parents  commit b951f9d

File tree

230 files changed

+74353
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+74353
-0
lines changed

.gitignore

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# latex extensions
2+
**_minted*
3+
**.log
4+
**.synctex.gz
5+
**.toc
6+
**.snm
7+
**.out
8+
**.nav
9+
**.aux
10+
**.aex
11+
**.pyg
12+
**.bbl
13+
**.blg
14+
**.synctex(busy)
15+
**.synctex.gz(busy)
16+
**.vrb
17+
**.dvi
18+
19+
# Python stuff
20+
**.py.un~
21+
22+
# vim stuff
23+
**.swp
24+
25+
# Byte-compiled / optimized / DLL files
26+
__pycache__/
27+
*.py[cod]
28+
*$py.class
29+
30+
# C extensions
31+
*.so
32+
33+
# Distribution / packaging
34+
.Python
35+
env/
36+
build/
37+
develop-eggs/
38+
dist/
39+
downloads/
40+
eggs/
41+
.eggs/
42+
lib/
43+
lib64/
44+
parts/
45+
sdist/
46+
var/
47+
wheels/
48+
*.egg-info/
49+
.installed.cfg
50+
*.egg
51+
52+
# PyInstaller
53+
# Usually these files are written by a python script from a template
54+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
55+
*.manifest
56+
*.spec
57+
58+
# Installer logs
59+
pip-log.txt
60+
pip-delete-this-directory.txt
61+
62+
# Unit test / coverage reports
63+
htmlcov/
64+
.tox/
65+
.coverage
66+
.coverage.*
67+
.cache
68+
nosetests.xml
69+
coverage.xml
70+
*.cover
71+
.hypothesis/
72+
73+
# Translations
74+
*.mo
75+
*.pot
76+
77+
# Django stuff:
78+
*.log
79+
local_settings.py
80+
81+
# Flask stuff:
82+
instance/
83+
.webassets-cache
84+
85+
# Scrapy stuff:
86+
.scrapy
87+
88+
# Sphinx documentation
89+
docs/_build/
90+
91+
# PyBuilder
92+
target/
93+
94+
# Jupyter Notebook
95+
.ipynb_checkpoints
96+
97+
# pyenv
98+
.python-version
99+
100+
# celery beat schedule file
101+
celerybeat-schedule
102+
103+
# SageMath parsed files
104+
*.sage.py
105+
106+
# dotenv
107+
.env
108+
109+
# virtualenv
110+
.venv
111+
venv/
112+
ENV/
113+
114+
# Spyder project settings
115+
.spyderproject
116+
.spyproject
117+
118+
# Rope project settings
119+
.ropeproject
120+
121+
# mkdocs documentation
122+
/site
123+
124+
# mypy
125+
.mypy_cache/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Charles Jekel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PythonProgrammingEML6934.pdf

161 KB
Binary file not shown.

exam/final_exam_review.pdf

104 KB
Binary file not shown.

exam/final_exam_review.tex

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
\documentclass[12pt]{article}
2+
3+
\setlength{\topmargin}{-.75in} \addtolength{\textheight}{2.00in}
4+
\setlength{\oddsidemargin}{.00in} \addtolength{\textwidth}{.75in}
5+
6+
\usepackage{amsmath,color,graphicx}
7+
\usepackage{minted}
8+
9+
\nofiles
10+
11+
\pagestyle{empty}
12+
13+
\setlength{\parindent}{0in}
14+
15+
16+
\begin{document}
17+
18+
\noindent {\sc {\bf {\Large Final review}}
19+
\hfill EML4930/6934, Python Programming, Fall 2017}
20+
\bigskip
21+
22+
\noindent {\sc {}
23+
\hfill {\large Name:}
24+
\hfill}
25+
\bigskip
26+
\bigskip
27+
28+
\textbf{Instructions:} Please answer the questions below. You are not allowed to use any notes or calculator on this Exam. You are not allowed to work with your neighbor.
29+
\bigskip
30+
31+
32+
\begin{enumerate}
33+
\item Name one difference between Python 2 and Python 3.
34+
\item Show a properly syntax single line comment in Python. Show a bulk/multi-line comment in Python.
35+
\item Consider floor division in Python 3. What will 3//2 return?
36+
\item Consider a list named x. What is the easiest way to call the last item in list x?
37+
\item How should you properly denote a code block in Python?
38+
\item Consider the following code:
39+
\begin{minted}
40+
{python}
41+
for i in range(100):
42+
print(i)
43+
\end{minted}
44+
What will be the first value of i? What will be the last value of i?
45+
\item Consider the following code:
46+
\begin{minted}
47+
{python}
48+
x = [1, 2, 3, 4, 5]
49+
y = [i**2 for i in x]
50+
\end{minted}
51+
List the values in y.
52+
\item Define a function solve the quadratic equation
53+
\begin{equation}
54+
ax^2 + bx + c = 0
55+
\end{equation} where $a,b,c$ are known numbers that are the input to your function. The solution is obtained as
56+
\begin{equation}
57+
x_1 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}, x_2 = \frac{-b + \sqrt{b^2 - 4ac}}{2a}
58+
\end{equation} and your function should return $x_1$ and $x_2$.
59+
\item What is the output of the following code
60+
\begin{minted}
61+
{python}
62+
x = 1
63+
def new_x():
64+
x = 2
65+
print(x)
66+
new_x()
67+
print(x)
68+
\end{minted}
69+
\item What is the name of the function within a class that runs automatically on each new instance of an object?
70+
\item Consider an object named a. What is one way to list all of the attributes (and methods) within the object a?
71+
\item How would you take the square root of 63.1516 in Python? (if you use a library you must stat the correct import)
72+
\item Consider a list name x that already contains a lot of information. Consider a list y = ['bob', 'loves Python', 87289]. How would you add y to the end of list x?
73+
\item z is a high dimensional numpy array. How would you find the index location of the maximum value of z?
74+
\item Code a:
75+
\begin{minted}
76+
{python}
77+
import numpy as np
78+
x = np.random.random(100000)
79+
y = []
80+
for i in x:
81+
y.append(2.0*x)
82+
y = np.array(y)
83+
\end{minted}
84+
85+
Code b:
86+
\begin{minted}
87+
{python}
88+
import numpy as np
89+
x = np.random.random(100000)
90+
y = 2.0*x
91+
\end{minted}
92+
93+
Code a and code b do the exact same thing. Which code will run faster? (a, b, or both will run the same speed) Why?
94+
\item Your friend is new to Python and programming. He is running the following code:
95+
\begin{minted}
96+
{python}
97+
from __future__ import division
98+
import numpy as np
99+
x = np.ones(10, dtype='int')
100+
y = np.random.random(10)
101+
for i in range(10):
102+
x[i] = y[i]/2.0
103+
\end{minted}
104+
but he keeps getting that x = array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]). Why is each item in x zero?
105+
\item given
106+
x = np.array([[4.0, 2.0],[-2.0,3.0]])
107+
108+
How would you transpose x?
109+
\item Write out the values in z
110+
\begin{minted}
111+
{python}
112+
x = np.array([[4.0, 2.0],
113+
[-2.0,3.0]])
114+
y = np.array([[2.0, 1.0],
115+
[0.0, 1.0])
116+
z = x*y
117+
\end{minted}
118+
\item Consider the following matrix multiplication
119+
\begin{equation}
120+
\begin{bmatrix}
121+
2 & 3 \\
122+
1 & 0 \\
123+
\end{bmatrix}\begin{bmatrix}
124+
5 & 2 \\
125+
1 & 3 \\
126+
\end{bmatrix}\begin{bmatrix}
127+
1 & 0 \\
128+
2 & 0 \\
129+
\end{bmatrix} = z
130+
\end{equation} Write out all the code (including imports) to solve for z in Python.
131+
\item Plot the function
132+
\begin{equation}
133+
y(x) = x^3 + 2x + 10.0
134+
\end{equation} on the domain \begin{equation}
135+
10 \leq x \leq 19
136+
\end{equation} using Python. Include all necessary imported libraries.
137+
\item Define a function that will return \textit{A}, \textit{B}. \textit{A} and \textit{B} are variables passed to the function. If B is not specified, it will default to a value of 1.0.
138+
\item Open readme.txt using Python and print the contents.
139+
\item What is the difference between
140+
\begin{minted}
141+
{python}
142+
f = open(myFile)
143+
\end{minted}
144+
and
145+
\begin{minted}
146+
{python}
147+
with open(myFile) as f:
148+
\end{minted}
149+
\item Why Does the following code produce x = array([0, 0, 1]) in Python?
150+
\begin{minted}
151+
{python}
152+
x = np.array((0,0,0))
153+
for i in range(3):
154+
x[i] = i/2.0
155+
\end{minted}
156+
Fix this code such that x = array([0.0, 0.5, 1.0]) after the for loop.
157+
\item Correct this code
158+
\begin{minted}
159+
{python}
160+
for i in range(10):
161+
if i > 5
162+
break
163+
\end{minted}
164+
such that it no longer produces this SyntaxError
165+
\begin{minted}
166+
{python}
167+
if i > 5
168+
^
169+
SyntaxError: invalid syntax
170+
\end{minted}
171+
\item Why would you use numpy.random.seed() when generating random numbers?
172+
\item Your friend wanted to grab the First item in the numpy array \textit{x}. Consider his code:
173+
\begin{minted}
174+
{python}
175+
x = np.random.random(100)
176+
y = x(1)
177+
\end{minted}
178+
produces the Following syntax error
179+
\begin{minted}
180+
{python}
181+
1 x = np.random.random(100)
182+
2 x = np.random.random(100)
183+
----> 3 y = x(1)
184+
185+
TypeError: 'numpy.ndarray' object is not callable
186+
\end{minted}
187+
What two things is your friend missing?
188+
\item What does the function \textit{os.system} do? Name a potential example where \textit{os.system} could be useful in a Python program?
189+
\item What is the Difference between Built-In Python libraries like os and math and libraries like numpy, pandas, and matplotlib?
190+
\item Consider
191+
\mint{python}|a = [0.0, 1.0, ['hi', 'world'], 2.0, 'blue']|
192+
what will
193+
\mint{python}|print(len(a))|
194+
return?
195+
\end{enumerate}
196+
197+
198+
\end{document}

0 commit comments

Comments
 (0)