Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
80c06f1
HW 1 Completed
Sep 10, 2020
e6be438
Added some comments
Sep 10, 2020
b63fd43
Minor Fix
Sep 10, 2020
8124952
Merge remote-tracking branch 'upstream/master' into dev
Sep 10, 2020
614f42b
Added docstring
Sep 10, 2020
f79fb1f
HW-1
Sep 17, 2020
b02cb1e
Merge remote-tracking branch 'upstream/master' into dev
Sep 17, 2020
f3451cc
HW3
Sep 17, 2020
a4130bc
HW 2 Quotes
Sep 17, 2020
edbd8fc
More Quotes
Sep 17, 2020
92c1cd6
Merge remote-tracking branch 'upstream/master' into dev
Sep 24, 2020
b154193
HW4 Progress
Oct 1, 2020
da5f722
Merge remote-tracking branch 'upstream/master' into dev
Oct 1, 2020
615dbae
HW 4 done
Oct 3, 2020
1775556
Merge remote-tracking branch 'upstream/master' into dev
Oct 3, 2020
0fce389
Comments Added for HW 4
Oct 3, 2020
c5bae96
HW 4 Small Changes
Oct 6, 2020
6e8a11f
HW 4 Adjustment
Oct 8, 2020
7f28e05
Merge remote-tracking branch 'upstream/master' into dev
Oct 8, 2020
b549a33
HW Update
Oct 14, 2020
8bbbf5c
Merge remote-tracking branch 'upstream/master' into dev
Oct 15, 2020
3637ac4
Pre HW
Oct 18, 2020
11a719f
Merge remote-tracking branch 'upstream/master' into dev
Oct 18, 2020
25ef048
HW 99%
Oct 19, 2020
df3072e
HW 5 Done
Oct 20, 2020
0741c7f
HW Finished
Oct 21, 2020
044edfe
Merge remote-tracking branch 'upstream/master' into dev
Oct 22, 2020
2b2c4a5
Changes
Nov 5, 2020
5548781
Merge remote-tracking branch 'upstream/master' into dev
Nov 5, 2020
b309952
Merge remote-tracking branch 'upstream/master' into dev
Nov 5, 2020
13187f0
Merge remote-tracking branch 'upstream/master' into dev
Nov 9, 2020
363da0a
Update 09_Data_Processing.ipynb
Nov 9, 2020
b54f9ba
HW 7 work
Nov 10, 2020
57647c1
HW 7 Done
Nov 10, 2020
3049ece
HW 7
Nov 12, 2020
f7fbbcf
Merge remote-tracking branch 'upstream/master' into dev
Nov 12, 2020
ef965b6
Merge remote-tracking branch 'upstream/master' into dev
Nov 17, 2020
867835b
Merge remote-tracking branch 'upstream/master' into dev
Nov 19, 2020
cc298db
workin
Nov 27, 2020
a8f8cfb
Merge remote-tracking branch 'upstream/master' into dev
Nov 27, 2020
10e14b4
Project coming along
Dec 3, 2020
85da9cf
Hoos r coming
Dec 3, 2020
18acf93
Finished I think
Dec 3, 2020
9f9b843
Almost
Dec 3, 2020
fda686c
Significant
Dec 4, 2020
18bec30
Analysis additions
Dec 4, 2020
a6e0422
changes oh changes
Dec 6, 2020
ad3952a
nothin but changes
Dec 6, 2020
780d3c1
more and more changes
Dec 6, 2020
d78194d
Finit
Dec 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
202 changes: 202 additions & 0 deletions assignments/A01_Python_Functions-jhr3kd-Copy1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assignment 1: Python Functions\n",
"## Computational Methods in Psychology (and Neuroscience)\n",
"### Psychology 4500/7559 --- Fall 2020\n",
"By: Per B. Sederberg, PhD\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Objectives\n",
"\n",
"Upon completion of this assignment, the student will be able to:\n",
"\n",
"1. Create and run a Python script\n",
"\n",
"2. Demonstrate the use of basic math and comparison operators\n",
"\n",
"3. Use conditional statements in Python\n",
"\n",
"4. Use the \"for\" statement to create loops\n",
"\n",
"5. Create custom functions, using parameters to make them generalizable\n",
"\n",
"6. Document code with in-code comments and docstrings\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Assignment\n",
"\n",
"- Read Think Python chapters 3, 5, and 6 (Functions, Conditionals and Recursion, and Fruitful Functions). Be sure to open a new Jupyter Notebook and type in \n",
" the examples as you read through the text. You can also try the Exercises\n",
" at the end of each chapter.\n",
"\n",
"- After you have read the chapters, write code in *this notebook* (***after making a copy and renaming it to have your userid in the title --- e.g., A01_Python_Functions_mst3k***) that performs the \n",
" following tasks:\n",
"\n",
" 1. Get two numbers from the user \n",
" 2. Compare the numbers\n",
" 3. If the first number is smaller than the second, calculate the mean\n",
" 4. If the first number is larger than the second, calculate the difference\n",
" 5. If the two numbers are the same, calculate the factorial using a custom function\n",
" 6. Display the results (indicating what operation you did)\n",
"\n",
"- Test your code and debug as necessary.\n",
"\n",
"- ***When you are done, save this notebook as HTML (`File -> Download as -> HTML`) and upload it to the matching assignment on UVACollab.***\n",
"\n",
"## HINTS\n",
"\n",
"- Be sure to comment your code\n",
"- Make use of the `input` function to get numbers (see examples from class)\n",
"- Use the template below to calculate the factorial using a non-recursive\n",
" function\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Name: Jerome Romualdez\n",
"# User ID: JHR3KD"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# ***finish this function replacing the `pass` with your code***\n",
"def factorial(n):\n",
" \"\"\"\n",
" Takes in a positive integer n and returns n!\n",
" \"\"\"\n",
" #***Did not include the input check and type check because I already have checks for those before I make the function call\n",
" # not needed already made check prior to call\n",
" # make sure the input is an integer greater than or equal to 1\n",
" if type(n) is not int:\n",
" pass # not needed already made check prior to call\n",
" \n",
" \n",
" # Initialize a variable to 1\n",
" y = 1\n",
" # Successively multiply the variable by the integers 2 up to n\n",
" #Multiplying by x + 1 because counting startes at 0\n",
" for x in range(n):\n",
" y *= (x+1)\n",
" \n",
" # return the result\n",
" return y\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter a number: 4\n",
"Enter another number: 4\n",
"The factorial of 4 is 24\n"
]
}
],
"source": [
"# ***your code here for reading in the numbers and operating correctly***\n",
"try:\n",
" x = int(input(\"Enter a number: \"))\n",
" y = int(input(\"Enter another number: \"))\n",
" if(x < 1 or y < 1):\n",
" raise Exception() \n",
" # first input is smaller than second so get mean\n",
" if(x < y):\n",
" mean = ((x+y)/2)\n",
" print(\"The mean of the two numbers is \" + str(mean))\n",
" #second input is smaller than first so get difference\n",
" elif (y < x):\n",
" diff = (x - y)\n",
" print(\"The difference of the two numbers is \" + str(diff))\n",
" #inputs are the same so call factorial()\n",
" else:\n",
" print(\"The factorial of \" + str(x) + \" is \" + str(factorial(x)))\n",
"except:\n",
" # if the input is not an int or is an int less than 1 display an error message\n",
" print(\"Please enter a positive integer!\")\n",
"\n",
"\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Challenge problem (not required, but fun!)\n",
"\n",
"- Re-write the factorial function using a recursive algorithm.\n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
"def factorial(n):\n",
" \"\"\"\n",
" Takes in a positive integer n and returns n!\n",
" Reccursive method\n",
" \"\"\"\n",
" #base case\n",
" if (n <= 1):\n",
" return 1\n",
" #recursive case\n",
" else: return factorial(n-1)* n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading