├── mod9_lab1.py ├── Module10 └── README.md ├── _config.yml ├── Module4 ├── months.txt ├── module4_lab2.zip ├── small_radish.txt ├── hw4_student_example_concise.py ├── module4_lab1.py ├── README.md ├── arg_parser.py ├── argparse.py ├── hw4_student_example_user_experience.py ├── hw3_error_checking2.py ├── Lab1.md ├── Lab2.md ├── hw3_error_checking1.py ├── module4_lab2_min_max_med_mean.py └── hw3_error_checking3.py ├── Module1 ├── test.tsv ├── madlib.zip ├── pics │ ├── .DS_Store │ ├── linux.jpg │ ├── bash_help.jpg │ ├── bash_shell.jpg │ ├── monty_python.jpg │ ├── run_python.jpg │ ├── install_python.jpg │ └── install_all_things.jpg ├── 2_why_learn_unix_python.md ├── 3_installing_stuff.md ├── README.md ├── .ipynb_checkpoints │ ├── Lab1_unix-checkpoint.ipynb │ ├── 2_why_learn_unix_python-checkpoint.ipynb │ ├── 3_installing_stuff-checkpoint.ipynb │ ├── 7_Troubleshooting-checkpoint.ipynb │ └── 1_course_overview-checkpoint.ipynb ├── unix_commands.txt ├── Lab1_unix.ipynb ├── 8_module1_lab2.ipynb ├── 7_Troubleshooting.ipynb └── 1_course_overview.ipynb ├── Module7 ├── github.jpg ├── lab1 │ ├── .DS_Store │ ├── 8_cli_clone.png │ ├── 9_see_stuff.png │ ├── 1_aftersignup.png │ ├── 7_click_clone.png │ ├── 3_verify_by_email.png │ ├── 6_see_your_new_repo.png │ ├── 2_click_start_project.png │ ├── 10_change_your_password.png │ ├── 5_fill_out_the_repository_form.png │ ├── 4_from_dashboard_click_new_repository.png │ └── Lab1.md ├── lab2 │ ├── 1_file.png │ ├── 2_edit.png │ ├── 3_comment.png │ ├── 4_commit.png │ └── Lab2.md ├── README.md ├── HW6_Review.ipynb ├── 2_github.md ├── 1_git.md ├── 4_final_projects.ipynb ├── iris_script.py └── 3_virtualenv.ipynb ├── Module5 ├── module5_lab1.zip ├── acct_balance.xlsx ├── hw4_student_example_concise.py ├── Lab2.md ├── lab2.py ├── README.md ├── hw4_student_example_the_hardway.py ├── hw4_student_example_user_experience.py ├── Lab1.md ├── HW4_review.ipynb ├── 1_Sets.ipynb ├── 2_tuples.ipynb └── 3_tuples.ipynb ├── Module6 ├── module6_lab1.zip ├── lab1 │ ├── __pycache__ │ │ └── data.cpython-35.pyc │ ├── question3.py │ ├── question1.py │ ├── question2.py │ ├── data.py │ └── question4.py ├── README.md ├── Lab1.md ├── 4_lightning_talks.ipynb ├── 2_more_user_args.ipynb ├── 3_exception_handling.ipynb ├── Lab2.md ├── iris_script.py ├── 5_lightning_talks.md ├── 5_lightning_talks.ipynb ├── 3_more_user_args.ipynb └── iris.csv ├── Module9 ├── top_sellers.png ├── 3_pandas_script.ipynb ├── top_sellers.tsv ├── README.md ├── Lab1.md ├── Lab2.md ├── pandas_script.py ├── lab2.py ├── lab1.py └── 2_more_classes.ipynb ├── Module2 ├── answer_lab2.py ├── README.md ├── module2_lab1.py ├── Module2_Lab2.ipynb ├── Module2_Lab1.ipynb ├── module2_lab1_answer.py ├── 2_python_data_contsructs.ipynb ├── .ipynb_checkpoints │ ├── 2_python_data_contsructs-checkpoint.ipynb │ └── 1_review_hw1-checkpoint.ipynb ├── 1_review_hw1.ipynb └── 4_String_Formatting.ipynb ├── Module3 ├── Lab1.md ├── Lab2.md ├── README.md ├── module3_lab2_solution.py └── 2_Functions.ipynb ├── Module8 ├── README.md ├── hw7_answer.py └── 1_install_jupyter.ipynb └── README.md /mod9_lab1.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Module10/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /Module4/months.txt: -------------------------------------------------------------------------------- 1 | Erasing all the things and adding this! -------------------------------------------------------------------------------- /Module1/test.tsv: -------------------------------------------------------------------------------- 1 | item1 20 2 | item2 3423 3 | item3 55666 4 | item4 12 -------------------------------------------------------------------------------- /Module1/madlib.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/madlib.zip -------------------------------------------------------------------------------- /Module7/github.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/github.jpg -------------------------------------------------------------------------------- /Module1/pics/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/.DS_Store -------------------------------------------------------------------------------- /Module1/pics/linux.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/linux.jpg -------------------------------------------------------------------------------- /Module4/module4_lab2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module4/module4_lab2.zip -------------------------------------------------------------------------------- /Module5/module5_lab1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module5/module5_lab1.zip -------------------------------------------------------------------------------- /Module6/module6_lab1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module6/module6_lab1.zip -------------------------------------------------------------------------------- /Module7/lab1/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/.DS_Store -------------------------------------------------------------------------------- /Module7/lab2/1_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab2/1_file.png -------------------------------------------------------------------------------- /Module7/lab2/2_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab2/2_edit.png -------------------------------------------------------------------------------- /Module9/top_sellers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module9/top_sellers.png -------------------------------------------------------------------------------- /Module1/pics/bash_help.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/bash_help.jpg -------------------------------------------------------------------------------- /Module5/acct_balance.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module5/acct_balance.xlsx -------------------------------------------------------------------------------- /Module7/lab2/3_comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab2/3_comment.png -------------------------------------------------------------------------------- /Module7/lab2/4_commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab2/4_commit.png -------------------------------------------------------------------------------- /Module1/pics/bash_shell.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/bash_shell.jpg -------------------------------------------------------------------------------- /Module1/pics/monty_python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/monty_python.jpg -------------------------------------------------------------------------------- /Module1/pics/run_python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/run_python.jpg -------------------------------------------------------------------------------- /Module7/lab1/8_cli_clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/8_cli_clone.png -------------------------------------------------------------------------------- /Module7/lab1/9_see_stuff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/9_see_stuff.png -------------------------------------------------------------------------------- /Module9/3_pandas_script.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [], 3 | "metadata": {}, 4 | "nbformat": 4, 5 | "nbformat_minor": 2 6 | } 7 | -------------------------------------------------------------------------------- /Module1/pics/install_python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/install_python.jpg -------------------------------------------------------------------------------- /Module7/lab1/1_aftersignup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/1_aftersignup.png -------------------------------------------------------------------------------- /Module7/lab1/7_click_clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/7_click_clone.png -------------------------------------------------------------------------------- /Module7/lab1/3_verify_by_email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/3_verify_by_email.png -------------------------------------------------------------------------------- /Module1/pics/install_all_things.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module1/pics/install_all_things.jpg -------------------------------------------------------------------------------- /Module7/lab1/6_see_your_new_repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/6_see_your_new_repo.png -------------------------------------------------------------------------------- /Module7/lab1/2_click_start_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/2_click_start_project.png -------------------------------------------------------------------------------- /Module7/lab1/10_change_your_password.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/10_change_your_password.png -------------------------------------------------------------------------------- /Module6/lab1/__pycache__/data.cpython-35.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module6/lab1/__pycache__/data.cpython-35.pyc -------------------------------------------------------------------------------- /Module7/lab1/5_fill_out_the_repository_form.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/5_fill_out_the_repository_form.png -------------------------------------------------------------------------------- /Module7/lab1/4_from_dashboard_click_new_repository.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/summerela/intro_programming_python/HEAD/Module7/lab1/4_from_dashboard_click_new_repository.png -------------------------------------------------------------------------------- /Module4/small_radish.txt: -------------------------------------------------------------------------------- 1 | Evie Pulsford - April Cross 2 | Matilda Condon - April Cross 3 | Samantha Mansell - Champion 4 | geronima trevisani - cherry belle 5 | Alexandra Shoebridge - Snow Belle 6 | -------------------------------------------------------------------------------- /Module2/answer_lab2.py: -------------------------------------------------------------------------------- 1 | 2 | def odd_or_even(i): 3 | if i%2 == 0: 4 | answer = 'even' 5 | else: 6 | answer = 'odd' 7 | return answer 8 | 9 | 10 | def for_this(j): 11 | for i in range(j): 12 | answer = odd_or_even(i) 13 | print("{} is {}".format(i, answer)) 14 | 15 | for_this(10) 16 | -------------------------------------------------------------------------------- /Module4/hw4_student_example_concise.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | f = open('airports.dat', encoding='utf8') 4 | 5 | reader = csv.reader(f, delimiter=',') 6 | 7 | for row in reader: 8 | airport = row[3] 9 | if airport == 'Russia' or airport == 'Australia': 10 | print('Row #' + str(reader.line_num) + ' ' + str(row)) 11 | 12 | 13 | -------------------------------------------------------------------------------- /Module5/hw4_student_example_concise.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | f = open('airports.dat', encoding='utf8') 4 | 5 | reader = csv.reader(f, delimiter=',') 6 | 7 | for row in reader: 8 | airport = row[3] 9 | if airport == 'Russia' or airport == 'Australia': 10 | print('Row #' + str(reader.line_num) + ' ' + str(row)) 11 | 12 | 13 | -------------------------------------------------------------------------------- /Module4/module4_lab1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | import sys 4 | 5 | def print_args(*args): 6 | for index, arg in enumerate(*args): 7 | print("[ ARG-{} ]: {}".format(index, arg)) 8 | 9 | # 10 | # using the sys module to list 11 | # the extra arguments passed to a script 12 | # 13 | print_args(sys.argv) 14 | 15 | -------------------------------------------------------------------------------- /Module9/top_sellers.tsv: -------------------------------------------------------------------------------- 1 | quantity unit_price belt_sales 2 | 164 724.29 10116.900000000001 3 | 171 1033.61 9509.880000000001 4 | 184 733.0300000000001 9359.26 5 | 149 965.71 8285.719999999998 6 | 147 640.67 8112.700000000001 7 | 106 601.04 6262.9400000000005 8 | 120 450.96 6033.53 9 | 83 412.07 5957.24 10 | 97 564.8 5894.38 11 | 133 551.83 5327.959999999999 12 | -------------------------------------------------------------------------------- /Module5/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module 5 Lab 2 2 | 3 | ## Instructions: 4 | Palindromes and anagrams. Whoohooo! 5 | 6 | 0. Create a script called `module5_lab2.py`. 7 | 8 | 0. Write a function that takes two strings and determines if they are anagrams. HINT: use a dictionary to count characters maybe. There are shorter ways to do this, but this one will flex our dictionary ninja foo! 9 | 10 | -------------------------------------------------------------------------------- /Module3/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module3 Lab1: 2 | 3 | ## Instructions 4 | 5 | 0. Create a script called `module3_lab1.py` in your personal workspace 6 | 7 | 0. Write a function called `odd_or_even` that takes a single integer as an argument. 8 | 9 | 0. For each integer passed into the function determine if it's odd or even and `print()` the answer and return the answer from the function 10 | 11 | -------------------------------------------------------------------------------- /Module9/README.md: -------------------------------------------------------------------------------- 1 | # Module 9: Object Oriented Programming 2 | 3 | ## [Review HW8](hw8_answer.ipynb) 4 | 5 | ## [Intro to OOP](1_OOP_basics.ipynb) 6 | 7 | ## [Lab1](Lab1.md) 8 | 9 | ## [More Classy with Classes](2_more_classes.ipynb) 10 | 11 | ## [Lab2](Lab2.md) 12 | 13 | ## [Pandas/Graphics in a script](pandas_script.py) 14 | 15 | ## [Final Project Guidlines](https://canvas.uw.edu/courses/1105303/assignments/3464484) 16 | -------------------------------------------------------------------------------- /Module5/lab2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def increment_counter(str1, counter): 4 | for s in str1: 5 | counter[s] = counter.get(s, 0) + 1 6 | return counter 7 | 8 | def is_anagram(str1, str2): 9 | # do QC here 10 | str1, str2 = str1.lower(), str2.lower() 11 | 12 | counter1 = increment_counter(str1, {}) 13 | counter2 = increment_counter(str2, {}) 14 | return counter1 == counter2 15 | 16 | print(is_anagram(sys.argv[1], sys.argv[2])) 17 | 18 | -------------------------------------------------------------------------------- /Module6/lab1/question3.py: -------------------------------------------------------------------------------- 1 | from data import movies, boxart 2 | 3 | 4 | # 5 | # Q3: write a function 6 | # that filters the List of 'movies' 7 | # into a new List of videos if a video has a rating equal to 5.0 8 | # but only return movie {id,title} pairs 9 | # 10 | 11 | # TODO: pairs = your_function() and make the test pass 12 | pairs = [] 13 | print("[ PAIRS ]: {}".format(pairs)) 14 | assert pairs == [ 15 | {'id': 654356453, 'title': 'Bad Boys'}, 16 | {'id': 675465, 'title': 'Fracture'} 17 | ] -------------------------------------------------------------------------------- /Module6/README.md: -------------------------------------------------------------------------------- 1 | # Module 6: More functions and how to fix them 2 | 3 | ## [Review HW5](https://canvas.uw.edu/courses/1105303/assignments/3464479) 4 | 5 | ## [More on Functions](1_more_functions.ipynb) 6 | 7 | ## [Builiding a Script With Functions](2_building_functions.ipynb) 8 | 9 | ## [Lab 1](Lab1.md) 10 | 11 | ## [Getting (more) User Args](3_more_user_args.ipynb) 12 | 13 | ## [Exception Handling](4_exception_handling.ipynb) 14 | 15 | ## [Lab 2](Lab2.md) 16 | 17 | ## [Introduce Lightning Talks](5_lightning_talks.ipynb) 18 | 19 | ## [Introduce HW6](https://canvas.uw.edu/courses/1105303/assignments/3464480) -------------------------------------------------------------------------------- /Module6/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module 6 Lab 1 2 | 3 | ## Instructions: 4 | 5 | Transformers, mount up! 6 | 7 | 0. Find the zipfile called `module6_lab1.zip` in this GitHub repository. Download and unzip it to your workspace. 8 | 9 | 0. Unzipped you should see a directory structure like this: 10 | 11 | ```bash 12 | module6_lab1/ 13 | ---- data.py 14 | ---- question1.py 15 | ---- question2.py 16 | ---- question3.py 17 | ---- question4.py 18 | ``` 19 | 20 | 0. Let's open the first two questions and read the specific instructions there together. 21 | 22 | 0. Questions 3 and 4 are for people who finish the other ones early 23 | -------------------------------------------------------------------------------- /Module7/README.md: -------------------------------------------------------------------------------- 1 | # Module 7: Github and Virtual Environments 2 | ## [Review Homework 6](iris_script.py) 3 | ## [Git](1_git.md) 4 | ## [Github](2_github.md) 5 | ## [Lab 1](https://github.com/summerela/intro_programming_python/blob/master/Module7/lab1/Lab1.md) 6 | ## [Working with Git: Let's Write a Script](https://github.com/summerela/intro_programming_python/blob/master/Module7/5_working_with_git.ipynb) 7 | ## [Lab 2](https://github.com/summerela/intro_programming_python/blob/master/Module7/lab2/Lab2.md) 8 | ## [Virtual Environments](3_virtualenv.ipynb) 9 | ## [Discuss Final Projects](4_final_projects.ipynb) 10 | ## [Introduce HW 7](https://canvas.uw.edu/courses/1105303/assignments/3464481) -------------------------------------------------------------------------------- /Module6/lab1/question1.py: -------------------------------------------------------------------------------- 1 | from data import movies, boxart 2 | 3 | 4 | # 5 | # Q1: 6 | # write a function called `transformer` 7 | # that takes the List 'movies' 8 | # and returns an List of {id,title} pairs 9 | # 10 | 11 | # TODO: write `transformer` function here 12 | 13 | # TODO: assign the variable `pairs` to the output List from `transformer` function to make the test pass 14 | # pairs = your_transformer_function() 15 | pairs = [] 16 | print("[ PAIRS ]: {}".format(pairs)) 17 | assert pairs == [ 18 | {'id': 70111470, 'title': 'Die Hard'}, 19 | {'id': 654356453, 'title': 'Bad Boys'}, 20 | {'id': 65432445, 'title': 'The Chamber'}, 21 | {'id': 675465, 'title': 'Fracture'} 22 | ] 23 | -------------------------------------------------------------------------------- /Module9/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module 9 Lab 1 2 | 3 | Classes are just different ways to organize the variables and functions you've already been writing. 4 | Think about them as containers for variables that the internal class functions should only be able to change 5 | 6 | ## Instructions: 7 | 8 | 0. Let's walk through `lab1.py` together and play with these two classes. We'll highlight some of things below that Summer was talking about in her lecture: 9 | 10 | 0. How to instantiate a class 11 | 12 | 0. `__init__`. When it runs. What goes in it. 13 | 14 | 0. `self`. What is it. What does it refer to 15 | 16 | 0. How to call functions on an instance. 17 | 18 | 0. Special functions in a class that you can "override" or use: `__str__`, `__repr__`, `__dict__` 19 | -------------------------------------------------------------------------------- /Module1/2_why_learn_unix_python.md: -------------------------------------------------------------------------------- 1 | ## Unix 2 | 3 | ![](./pics/linux.jpg?raw=true) 4 | 5 | If you're serious about becoming a programmer, it's essential to at least learn the basics of a command line interface, and Unix is the top choice. 6 | 7 | - Run commands and navigate directly from the command line 8 | - Memory efficiency 9 | - Directly run scripts without the need for extra software/interface 10 | - Most common server OS 11 | - Steep learning curve, but worth it 12 | 13 | ## Python 14 | ![](./pics/monty_python.jpg?raw=true) 15 | 16 | - It's named after Monty Python... what more could you want? 17 | - Easy to read 18 | - Powerful 19 | - Frequently updated 20 | - Many powerful and useful modules 21 | - Easy, clear syntax 22 | - Platform agnostic 23 | -------------------------------------------------------------------------------- /Module2/README.md: -------------------------------------------------------------------------------- 1 | # Module 2 2 | 3 | ## [Review Assignment 1](https://canvas.uw.edu/courses/1105303/assignments/3464475) 4 | 5 | ## [Python Data Constructs](https://github.com/summerela/intro_programming_python/blob/master/Module2/2_python_data_contsructs.ipynb) 6 | 7 | ## [Lab1: Formatting Lab](Module2_Lab1.ipynb) 8 | 9 | 10 | ## [Operations](https://github.com/summerela/intro_programming_python/blob/master/Module2/3_Operations.ipynb) 11 | 12 | ## [Module 2: Operations Lab](Module2_Lab2.ipynb) 13 | 14 | 15 | ## [String formatting in python](https://github.com/summerela/intro_programming_python/blob/master/Module2/4_String_Formatting.ipynb) 16 | 17 | ## [Intro to Data Types](5_data_types.ipynb) 18 | 19 | ## [Module 2 Homework](https://canvas.uw.edu/courses/1105303/assignments/3464476) 20 | -------------------------------------------------------------------------------- /Module5/README.md: -------------------------------------------------------------------------------- 1 | # Module 5: Dictionaries, Sets and Tuples 2 | 3 | ## [Review HW 4](https://canvas.uw.edu/courses/1105303/assignments/3464478) 4 | 5 | ## [Sets](https://github.com/summerela/intro_programming_python/blob/master/Module5/1_Sets.ipynb) 6 | 7 | ## [Parsing a TSV File](https://github.com/summerela/intro_programming_python/blob/master/Module5/2_parsingTSV.ipynb) 8 | 9 | ## [Module 5 Lab 1](Lab1.md) 10 | 11 | ## [Tuples](https://github.com/summerela/intro_programming_python/blob/master/Module5/3_tuples.ipynb) 12 | 13 | ## [Dictionaries](https://github.com/summerela/intro_programming_python/blob/master/Module5/4_dictionaries.ipynb) 14 | 15 | ## [Module 5 Lab 2](Lab2.md) 16 | 17 | ## [Introduce HW 5](https://canvas.uw.edu/courses/1105303/assignments/3464479) 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Module3/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module3 Lab2: 2 | 3 | ## Instructions 4 | 5 | 0. Create a script called `module3_lab2.py` in your personal workspace 6 | 7 | 0. Write a function called `odd_or_even` that takes a single integer as an argument. 8 | 9 | 0. Inside the function write a loop that will iterate from 0 until the integer argument. Note: read about [.range()](https://docs.python.org/3/library/stdtypes.html#typesseq-range). 10 | 11 | 0. For each integer in the for loop `print()` out if it is odd or even to the console. 12 | 13 | 0. Using `print()` seems not functional. Try returning a list of all odd-or-even answers. For example, the call input and output in the Python 14 | interpreter might look like this: 15 | 16 | ```bash 17 | In [1]: odd_or_even(3) 18 | Out[1]: [answer1, answer2, answer3] 19 | ``` 20 | -------------------------------------------------------------------------------- /Module4/README.md: -------------------------------------------------------------------------------- 1 | # Module 4: 2 | # Modules, Files and Advanced List/String Operations 3 | 4 | ## [Importing Modules: How not to reinvent the wheel](https://github.com/summerela/intro_programming_python/blob/master/Module4/1_Importing_Modules.ipynb) 5 | 6 | ## [File Handling](https://github.com/summerela/intro_programming_python/blob/master/Module4/2_File_Handling.ipynb) 7 | 8 | ## [Module 4 Lab 1](Lab1.md) 9 | 10 | ## [Parsing Text: Advanced String Operations](https://github.com/summerela/intro_programming_python/blob/master/Module4/3_parsing_text.ipynb) 11 | 12 | ## [More Fun with Functions and Lists](https://github.com/summerela/intro_programming_python/blob/master/Module4/4_more_functions.ipynb) 13 | 14 | ## [Module 4 Lab 2](Lab2.md) 15 | 16 | ## [Homework 4](https://canvas.uw.edu/courses/1105303/assignments/3464478) 17 | 18 | -------------------------------------------------------------------------------- /Module7/HW6_Review.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 6 Review" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [] 18 | } 19 | ], 20 | "metadata": { 21 | "kernelspec": { 22 | "display_name": "Python 3", 23 | "language": "python", 24 | "name": "python3" 25 | }, 26 | "language_info": { 27 | "codemirror_mode": { 28 | "name": "ipython", 29 | "version": 3 30 | }, 31 | "file_extension": ".py", 32 | "mimetype": "text/x-python", 33 | "name": "python", 34 | "nbconvert_exporter": "python", 35 | "pygments_lexer": "ipython3", 36 | "version": "3.5.2" 37 | } 38 | }, 39 | "nbformat": 4, 40 | "nbformat_minor": 2 41 | } 42 | -------------------------------------------------------------------------------- /Module6/4_lightning_talks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Lightning Talks" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [] 18 | } 19 | ], 20 | "metadata": { 21 | "kernelspec": { 22 | "display_name": "Python 3", 23 | "language": "python", 24 | "name": "python3" 25 | }, 26 | "language_info": { 27 | "codemirror_mode": { 28 | "name": "ipython", 29 | "version": 3 30 | }, 31 | "file_extension": ".py", 32 | "mimetype": "text/x-python", 33 | "name": "python", 34 | "nbconvert_exporter": "python", 35 | "pygments_lexer": "ipython3", 36 | "version": "3.5.2" 37 | } 38 | }, 39 | "nbformat": 4, 40 | "nbformat_minor": 2 41 | } 42 | -------------------------------------------------------------------------------- /Module6/2_more_user_args.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# More on User Args" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [] 18 | } 19 | ], 20 | "metadata": { 21 | "kernelspec": { 22 | "display_name": "Python 3", 23 | "language": "python", 24 | "name": "python3" 25 | }, 26 | "language_info": { 27 | "codemirror_mode": { 28 | "name": "ipython", 29 | "version": 3 30 | }, 31 | "file_extension": ".py", 32 | "mimetype": "text/x-python", 33 | "name": "python", 34 | "nbconvert_exporter": "python", 35 | "pygments_lexer": "ipython3", 36 | "version": "3.5.2" 37 | } 38 | }, 39 | "nbformat": 4, 40 | "nbformat_minor": 2 41 | } 42 | -------------------------------------------------------------------------------- /Module6/3_exception_handling.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Exception Handling" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": null, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [] 18 | } 19 | ], 20 | "metadata": { 21 | "kernelspec": { 22 | "display_name": "Python 3", 23 | "language": "python", 24 | "name": "python3" 25 | }, 26 | "language_info": { 27 | "codemirror_mode": { 28 | "name": "ipython", 29 | "version": 3 30 | }, 31 | "file_extension": ".py", 32 | "mimetype": "text/x-python", 33 | "name": "python", 34 | "nbconvert_exporter": "python", 35 | "pygments_lexer": "ipython3", 36 | "version": "3.5.2" 37 | } 38 | }, 39 | "nbformat": 4, 40 | "nbformat_minor": 2 41 | } 42 | -------------------------------------------------------------------------------- /Module6/lab1/question2.py: -------------------------------------------------------------------------------- 1 | from data import movies, boxart 2 | 3 | 4 | 5 | # 6 | # Q2: write a function called `filterer` 7 | # that takes a the full List of `movies` and 8 | # returns a List of videos if a video has a rating equal to 5.0 9 | # 10 | 11 | # TODO: write `filterer` function here 12 | 13 | # TODO: assign the variable `matches` to the output List from `filterer` function to make the test pass 14 | # matches = your_filterer_function() 15 | 16 | matches = [] 17 | print("[ MATCHES ]: {}".format(matches)) 18 | assert matches == [ 19 | 20 | {'rating': 5.0, 'title': 'Bad Boys', 'bookmark':[{'id': 432534, 'time': 65876586}] 21 | ,'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 654356453}, 22 | 23 | {'rating': 5.0, 'title': 'Fracture', 'bookmark': [{'id': 432534, 'time': 65876587}] 24 | ,'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 675465} 25 | ] 26 | -------------------------------------------------------------------------------- /Module3/README.md: -------------------------------------------------------------------------------- 1 | # Module 3 2 | 3 | ## [Review HW 2](https://canvas.uw.edu/courses/1105303/assignments/3464476) 4 | 5 | ## [Data Type Conversion and Augmented Expressions](https://github.com/summerela/intro_programming_python/blob/master/Module3/1_data_type_conversions.ipynb) 6 | 7 | ## [Functions](https://github.com/summerela/intro_programming_python/blob/master/Module3/2_Functions.ipynb) 8 | 9 | ## [Conditional Operations](https://github.com/summerela/intro_programming_python/blob/master/Module3/3_Conditionals.ipynb) 10 | 11 | ## [Module3 Lab1 -- Functions and Conditionals](Lab1.md) 12 | 13 | ## [Lists](https://github.com/summerela/intro_programming_python/blob/master/Module3/4_Lists.ipynb) 14 | 15 | ## [For loops](https://github.com/summerela/intro_programming_python/blob/master/Module3/5_Iteration_Loops.ipynb) 16 | 17 | ## [Module3 Lab2 -- Loops and Lists](Lab2.md) 18 | 19 | ## [Homework 3](https://canvas.uw.edu/courses/1105303/assignments/3464477) 20 | -------------------------------------------------------------------------------- /Module6/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module 6 Lab 2 2 | 3 | ## Instructions: 4 | 5 | When you try to `open` a file that doesn't exist on your file system the `open` function raises a nice error called `FileNotFoundError` 6 | 7 | ```bash 8 | >>> open('some_file_location.txt', 'r') 9 | Traceback (most recent call last): 10 | File "", line 1, in 11 | FileNotFoundError: [Errno 2] No such file or directory: 'some_file_location.txt' 12 | >>> 13 | ``` 14 | 15 | 0. Write a script called `lab2.py`. In the script write some pseudo code that opens a non-existant file location 16 | and use `try/except` to handle the `FileNotFoundError` and output a nicer message for the user about what happened? 17 | 18 | 0. Let's say some other type of error happens but we don't know the specifc name of it. How can our `try/except` handle this? 19 | 20 | 0. Files must always be closed! If an error is thrown how can we assure the file still gets closed? HINT: look up `try/except/finally` 21 | 22 | -------------------------------------------------------------------------------- /Module9/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module 9 Lab 2 2 | 3 | We love iris flowers in this class. Let's return to the [iris.csv](https://github.com/summerela/intro_programming_python/blob/master/Module6/iris.csv) dataset in this lab and try to write our simple statistics 4 | inside classes. 5 | 6 | ## Instructions: 7 | 8 | 0. Copy `lab2.py` to your workspace 9 | 10 | 0. Look for `TODO1` in the code. Can you finish writing this function without accessing any variables outside of the `IrisStats` class? 11 | 12 | 0. Look for `TODO2` in the code. Can you finish writing this function without accessing any variables outside of the `IrisStats` class? 13 | 14 | 0. The final TODO is a little harder to explain. The idea is that we don't want to read the csv for every statistical function we write because it's repetative. There should be multiple ways to refactor the code to read the file once and cache the `self.iris_data` read from the csv. This can be done in the `IrisReader` or `IrisStats` class. So you have options. 15 | -------------------------------------------------------------------------------- /Module1/3_installing_stuff.md: -------------------------------------------------------------------------------- 1 | # Installing all the things! 2 | 3 | ![](./pics/install_all_things.jpg?raw=true) 4 | 5 | Try to follow along, but if you get stuck, don't worry, we'll have time during the lab to make sure you're setup and running. 6 | 7 | ## Setting up a Unix Environment 8 | ### Terminal in Mac 9 | OSx is based off of unix, so accessing the command line from a mac is super easy; just hit command + spacebar and search for "terminal". 10 | 11 | ### GitBash in Windows 12 | Since Windows is based off of DOS instead of UNIX, we'll use Git Bash to keep things from getting too complicated. 13 | 14 | ## Install Git 15 | 16 | - Download the most recent windows or mac version from: 17 | https://git-scm.com/downloads 18 | 19 | ## Install Python3 20 | - Download the most recent version of python3 for mac or windows from: https://www.python.org/downloads/ 21 | 22 | ## Installing Sublime Text 23 | - Download the most recent version of sublime text version 2 for mac or windows from: 24 | http://www.sublimetext.com/2 25 | -------------------------------------------------------------------------------- /Module5/hw4_student_example_the_hardway.py: -------------------------------------------------------------------------------- 1 | #import sys 2 | import csv 3 | #import os 4 | 5 | Rus_ports_nos = [] 6 | Aus_ports_nos = [] 7 | Other_countries = [] 8 | 9 | in_file = open("./airports.dat", "r", encoding='utf-8') 10 | 11 | #the following reads through the input file and creates new variable lists with just the 12 | #Australia and Russia data in it. 13 | for line in in_file: 14 | line = line.strip() 15 | parts = line.split(",") 16 | if parts[3] == '"Russia"': 17 | Rus_ports_nos.append(parts) 18 | elif parts[3] == '"Australia"': 19 | Aus_ports_nos.append(parts) 20 | else: 21 | Other_countries.append(parts[3]) 22 | 23 | print("The data for Russian airports listed are {}.\n \ 24 | The airports listed in Australia are {}.".format(Rus_ports_nos,Aus_ports_nos)) 25 | 26 | print ("There are {} Russian airports listed, {} Australian airports listed, \ 27 | and {} other countries airports listed.".format(len(Rus_ports_nos),len(Aus_ports_nos),len(Other_countries))) 28 | 29 | in_file.close() 30 | -------------------------------------------------------------------------------- /Module4/arg_parser.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | import sys 4 | import argparse 5 | 6 | def print_args(*args): 7 | print("[ ARGS ]: {}".format(args)) 8 | 9 | # 10 | # best option is to use `argparse` module 11 | # 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument('--foo', help='Enable `foo` checking with this flag', action='store_true') 14 | parser.add_argument('--bar', help='The number of `bar`s in your program', type=int, choices=[1,2,3], required=True) 15 | parser.add_argument('--baz', help='A list of `baz`s in your program', nargs='+', required=True) 16 | 17 | # get the arguments passed to the command line 18 | args = parser.parse_args() 19 | 20 | # note: they are part of a `Namespace` object 21 | print_args( args ) 22 | 23 | # access the arguments passed to the command line 24 | if args.foo is True: 25 | print("[ FOO ]: {}".format(args.foo)) 26 | else: 27 | print("[ FOO ]: False") 28 | 29 | print("[ BAR ]: {}".format('Bar ' * args.bar)) 30 | 31 | print("[ BAZ LIST ]: {}".format(args.baz)) 32 | -------------------------------------------------------------------------------- /Module4/argparse.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | import sys 4 | import argparse 5 | 6 | def print_args(*args): 7 | print("[ ARGS ]: {}".format(args)) 8 | 9 | # 10 | # best option is to use `argparse` module 11 | # 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument('--foo', help='Enable `foo` checking with this flag', action='store_true') 14 | parser.add_argument('--bar', help='The number of `bar`s in your program', type=int, choices=[1,2,3], required=True) 15 | parser.add_argument('--baz', help='A list of `baz`s in your program', nargs='+', required=True) 16 | 17 | # get the arguments passed to the command line 18 | args = parser.parse_args() 19 | 20 | # note: they are part of a `Namespace` object 21 | print_args( args ) 22 | 23 | # access the arguments passed to the command line 24 | if args.foo is True: 25 | print("[ FOO ]: {}".format(args.foo)) 26 | else: 27 | print("[ FOO ]: False") 28 | 29 | print("[ BAR ]: {}".format('Bar ' * args.bar)) 30 | 31 | print("[ BAZ LIST ]: {}".format(args.baz)) 32 | -------------------------------------------------------------------------------- /Module9/pandas_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import pandas as pd 4 | import matplotlib.pyplot as plt 5 | 6 | # import csv from URL as dataframe 7 | url = "http://pbpython.com/extras/sample-salesv2.csv" 8 | sales = pd.read_csv(url) 9 | 10 | # update column names to remove spaces 11 | sales.columns = ['acct_num', 'name', 'sku', 'category', 'quantity', 'unit_price', 'ext_price', 'date'] 12 | 13 | # subset data to contain only belt sales 14 | belt_df = sales[['name', 'category', 'quantity', 'unit_price']] 15 | belt_df = belt_df[belt_df['category']== 'Belt'] 16 | 17 | # create a new column called belt_sales 18 | belt_df['belt_sales'] = belt_df.quantity * belt_df.unit_price 19 | 20 | # group sales by company name 21 | belts_by_company = belt_df.groupby('name').sum() 22 | 23 | # subset for top 10 best sellers 24 | top_sellers = belts_by_company.sort_values(by='belt_sales', ascending=False).head(10) 25 | 26 | # save top 10 data frame to tsv 27 | top_sellers.to_csv("./top_sellers.tsv", sep="\t", index=None) 28 | 29 | # save plot to file 30 | top_sellers.plot() 31 | plt.savefig('./top_sellers.png') 32 | 33 | -------------------------------------------------------------------------------- /Module4/hw4_student_example_user_experience.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import csv 4 | 5 | #converting file to csv format 6 | airports = open("./airports.dat.txt") 7 | readairports = csv.reader(airports) 8 | 9 | #set initial counter for russian & aussie airports to 0 10 | russia = 0 11 | auz = 0 12 | 13 | #loop searches for russian and australian airports and prints them out 14 | #also russian & aussie airport counter increases by 1 15 | for location in readairports: 16 | if location[3] == "Australia": 17 | #limited index range to clean up data and redundant info 18 | print(location[0:9]) 19 | auz += 1 20 | elif location[3] == "Russia": 21 | #limited index range to clean up data and redundant info 22 | print(location[0:9]) 23 | russia += 1 24 | else: 25 | #skips row if no match for russian & australian airports 26 | continue 27 | 28 | #printing totals from completed for loop of russian & australian airports 29 | print("There are {} russian airports.".format(russia)) 30 | print("There are {} australian airports.".format(auz)) 31 | 32 | airports.close() 33 | -------------------------------------------------------------------------------- /Module5/hw4_student_example_user_experience.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import csv 4 | 5 | #converting file to csv format 6 | airports = open("./airports.dat.txt") 7 | readairports = csv.reader(airports) 8 | 9 | #set initial counter for russian & aussie airports to 0 10 | russia = 0 11 | auz = 0 12 | 13 | #loop searches for russian and australian airports and prints them out 14 | #also russian & aussie airport counter increases by 1 15 | for location in readairports: 16 | if location[3] == "Australia": 17 | #limited index range to clean up data and redundant info 18 | print(location[0:9]) 19 | auz += 1 20 | elif location[3] == "Russia": 21 | #limited index range to clean up data and redundant info 22 | print(location[0:9]) 23 | russia += 1 24 | else: 25 | #skips row if no match for russian & australian airports 26 | continue 27 | 28 | #printing totals from completed for loop of russian & australian airports 29 | print("There are {} russian airports.".format(russia)) 30 | print("There are {} australian airports.".format(auz)) 31 | 32 | airports.close() 33 | -------------------------------------------------------------------------------- /Module8/README.md: -------------------------------------------------------------------------------- 1 | # Module 8 2 | Reminder: 3 | - Class is completely online next week. 4 | - Wednesday office hours are online next week. 5 | - Office hours for Sunday, March 12th moved to Monday, March 13th at 8pm 6 | 7 | ## [Review Homework 7](https://github.com/summerela/intro_programming_python/blob/master/Module8/hw7_answer.py) 8 | ## [Install Jupyter Notebook](https://github.com/summerela/intro_programming_python/blob/master/Module8/1_install_jupyter.ipynb) 9 | ## [Working with Jupyter Notebook: Interactive Python Notebooks](https://github.com/summerela/intro_programming_python/blob/master/Module8/2_using_jupyter.ipynb) 10 | ## [A Brief Introduction to Data Analysis with Pandas](https://github.com/summerela/intro_programming_python/blob/master/Module8/3_pandas.ipynb) 11 | ## [Practice with a Data Analysis Pipeline](https://github.com/summerela/intro_programming_python/blob/master/Module8/4_Analysis_Pipeline.ipynb) 12 | ## [Sign Up For Lightning Talks](https://canvas.uw.edu/courses/1105303/discussion_topics/3701010) 13 | ## [Introduce HW 8](https://github.com/summerela/intro_programming_python/blob/master/Module8/HW8.ipynb) 14 | -------------------------------------------------------------------------------- /Module2/module2_lab1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | 4 | header = ['FirstName', 'LastName', 'City', 'Zipcode'] 5 | row1 = ['Greg', 'Corradini', 'Minneapolis', '75432'] 6 | row2 = ['Summer', 'Rae', 'Seattle', '98103'] 7 | # this nested list `table` represents 8 | a table of rows where the first row 9 | # is the column headers 10 | table = [ 11 | header, 12 | row1, 13 | row2, 14 | ] 15 | 16 | calculate the max width of the table cell 17 | padding = 2 18 | max_width = 0 19 | for row in table: 20 | new_max = max([len(value) for value in row]) + padding 21 | # only set thew new max if it's actually greater 22 | if new_max > max_width: 23 | max_width = new_max 24 | 25 | 26 | print out each row of the table 27 | for row in table: 28 | cell1, cell2, cell3, cell4 = row 29 | 30 | # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to a table 31 | # 32 | # |FirstName |LastName |City |Zipcode | 33 | # |Greg |Corradini |Minneapolis |75432 | 34 | # |Summer |Rae |Seattle |98103 | 35 | # 36 | # WRITE YOUR CODE BELOW: 37 | print(cell1,cell2,cell3,cell4, sep='|') -------------------------------------------------------------------------------- /Module6/lab1/data.py: -------------------------------------------------------------------------------- 1 | movies = [ 2 | { 3 | "id": 70111470, 4 | "title": "Die Hard", 5 | "uri": "http://api.netflix.com/catalog/titles/movies/70111470", 6 | "rating": 4.0, 7 | "bookmark": [] 8 | }, 9 | { 10 | "id": 654356453, 11 | "title": "Bad Boys", 12 | "uri": "http://api.netflix.com/catalog/titles/movies/70111470", 13 | "rating": 5.0, 14 | "bookmark": [{ "id":432534, "time":65876586 }] 15 | }, 16 | { 17 | "id": 65432445, 18 | "title": "The Chamber", 19 | "uri": "http://api.netflix.com/catalog/titles/movies/70111470", 20 | "rating": 4.0, 21 | "bookmark": [] 22 | }, 23 | { 24 | "id": 675465, 25 | "title": "Fracture", 26 | "uri": "http://api.netflix.com/catalog/titles/movies/70111470", 27 | "rating": 5.0, 28 | "bookmark": [{ "id":432534, "time":65876587 }] 29 | } 30 | ] 31 | 32 | boxart = [ 33 | { "width": 200, "height":200, "url":"http://cdn-0.nflximg.com/images/2891/DieHard.jpg" }, 34 | { "width": 150, "height":200, "url":"http://cdn-0.nflximg.com/images/2891/BadBoys.jpg" }, 35 | { "width": 300, "height":200, "url":"http://cdn-0.nflximg.com/images/2891/TheChamber.jpg" }, 36 | { "width": 425, "height":150, "url":"http://cdn-0.nflximg.com/images/2891/Fracture.jpg" } 37 | ] -------------------------------------------------------------------------------- /Module7/2_github.md: -------------------------------------------------------------------------------- 1 | # Github 2 | Social code repository 3 | - Open source code is usually posted up here 4 | - You can download, edit, use, contribute 5 | - Great for development teams 6 | - Version control for your project 7 | - Great to have your own project repo for prospective employers 8 | 9 | ## Repo Basics 10 | Each github repo has a basic structure. 11 | 12 | We'll use the pandas module as an example: 13 | https://github.com/pandas-dev/pandas 14 | 15 | - README.md - Create an introduction to your code, how to install, and how to use it. 16 | - View the program languages included 17 | - Star the page for easy return, like a bookmark 18 | - Read a wiki for help on installing and using the program 19 | - Watch the repo for changes/updates/bug fixes 20 | - Get a link to clone or download the repo 21 | - Issues - Read up on or report bugs 22 | - Interactive code review 23 | - Submit a pull request to add your own code to the repo 24 | 25 | ## Niceties 26 | - [Github pages](https://guides.github.com/features/pages/): create a repo for your website 27 | - [Github integrations](https://github.com/integrations): apps that enhance your gethub experience 28 | - [Interactive Ipython Notebooks](http://mybinder.org/): run Jupyter Notebook live off of github 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Module6/iris_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import csv 5 | 6 | def read_in_csv(file_path): 7 | f = open(file_path) 8 | my_file = csv.reader(f) 9 | return my_file 10 | 11 | def get_column_unique(in_file, col_number): 12 | col_list = [] 13 | my_file = read_in_csv(in_file) 14 | for row in my_file: 15 | col_list.append(row[col_number]) 16 | unique_vals = set(col_list) 17 | unique_length = len(unique_vals) 18 | return unique_length 19 | 20 | def count_things(in_file, col_number): 21 | my_dict = {} 22 | my_file = read_in_csv(in_file) 23 | 24 | # loop through dictionary to track name and count 25 | for row in my_file: 26 | key_name = row[col_number] 27 | 28 | # for every row, check if the class_name is in the dictionary 29 | if key_name in my_dict: 30 | my_dict[key_name] = my_dict[key_name] + 1 31 | 32 | # if not, add it, and set the count to 1 33 | else: 34 | my_dict[key_name] = 1 35 | 36 | return my_dict 37 | 38 | 39 | # have the user specify input file 40 | my_file = "./iris.csv" 41 | 42 | unique_vals = get_column_unique(my_file, 4) 43 | count_classes = count_things(my_file, 4) 44 | 45 | print(unique_vals) 46 | print(count_classes) 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IT FDN 100 B: Foundations Of Programming with Python 2 | Lecture Material for UW Course "Intro to Programming with Python" 3 | 4 | ## [Module 1: Unix Basics](https://github.com/summerela/intro_programming_python/tree/master/Module1) 5 | 6 | ## [Module 2: Python Data Constructs and String Formatting](https://github.com/summerela/intro_programming_python/tree/master/Module2) 7 | 8 | ## [Module 3: Functions, Lists and Loops](https://github.com/summerela/intro_programming_python/tree/master/Module3) 9 | 10 | ## [Module 4: Modules, Files and Advanced List/String Operations](https://github.com/summerela/intro_programming_python/tree/master/Module4) 11 | 12 | ## [Module 5: Dictionaries, Sets and Tuples](https://github.com/summerela/intro_programming_python/tree/master/Module5) 13 | 14 | ## [Module 6: More functions and how to fix them (Exception Handling)](https://github.com/summerela/intro_programming_python/tree/master/Module6) 15 | 16 | ## [Module 7: GitHub and Virtual Environments](https://github.com/summerela/intro_programming_python/tree/master/Module7) 17 | 18 | ## [Module 8: Jupyter Notebooks and Pandas](https://github.com/summerela/intro_programming_python/tree/master/Module8) 19 | 20 | ## [Module 9: Object Oriented Programming](https://github.com/summerela/intro_programming_python/tree/master/Module9) 21 | -------------------------------------------------------------------------------- /Module1/README.md: -------------------------------------------------------------------------------- 1 | # Module 1 2 | ## [How the Course Works](https://github.com/summerela/intro_programming_python/blob/master/Module1/1_course_overview.ipynb) 3 | 4 | ## [Why Learn Unix and Python?](https://github.com/summerela/intro_programming_python/blob/master/Module1/2_why_learn_unix_python.md) 5 | 6 | ## [Installing Stuff](https://github.com/summerela/intro_programming_python/blob/master/Module1/3_installing_stuff.md) 7 | 8 | ## [Unix Basics](https://github.com/summerela/intro_programming_python/blob/master/Module1/4_unix_basics.ipynb) 9 | 10 | ## [Module1 Lab1: Unix Basics](https://github.com/summerela/intro_programming_python/blob/master/Module1/Lab1_unix.ipynb) 11 | 12 | ## [Running Python](https://github.com/summerela/intro_programming_python/blob/master/Module1/5_Running_Python.ipynb) 13 | 14 | ## [Programming Basics](https://github.com/summerela/intro_programming_python/blob/master/Module1/6_Programming_Basics.ipynb) 15 | 16 | ## [Module1 Lab2: Creating and running a python script](https://github.com/summerela/intro_programming_python/blob/master/Module1/8_module1_lab2.ipynb) 17 | 18 | ## [How to Troubleshoot](https://github.com/summerela/intro_programming_python/blob/master/Module1/7_Troubleshooting.ipynb) 19 | 20 | ## [Homework](https://canvas.uw.edu/courses/1105303/assignments/3464475?module_item_id=7076570) 21 | -------------------------------------------------------------------------------- /Module4/hw3_error_checking2.py: -------------------------------------------------------------------------------- 1 | """ This script asks the users for two numbers, places them in a list, 2 | then tells the user the index location of each number, and if it is 3 | divisible by 3. 4 | 5 | The user could break this script by not providing a minimum number 6 | that is less than the maximum number. I have used while to prompt 7 | the user to enter a new maximum, if it is less than or equal to minimum """ 8 | 9 | #!/bin/env python 10 | 11 | var1 = int(input("Enter a minimum number: ")) 12 | var2 = int(input("Enter a maximum number: ")) 13 | 14 | # this checks that the user has entered a maximum that is greater than the minimum 15 | while var1 >= var2: 16 | var2 = int(input("The maximum cannot be less than or equal to the minimum. Please try again: ")) 17 | 18 | 19 | # this allows the maximum number to be included in the list 20 | var3 = var2 + 1 21 | 22 | my_list = list(range(var1, var3)) 23 | 24 | def list_numbers(num): 25 | for index, my_num in enumerate(num): 26 | print("The number {} is at index {}".format(my_num, index)) 27 | 28 | list_numbers(my_list) 29 | 30 | def divide_numbers(num): 31 | for x in num: 32 | if x % 3 == 0: 33 | print("The number {} is divisible by 3".format(x)) 34 | else: 35 | pass 36 | 37 | divide_numbers(my_list) 38 | 39 | quit() 40 | -------------------------------------------------------------------------------- /Module4/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module 4 Lab 1 2 | 3 | ## Instructions: 4 | 5 | You're a programmer with no time. Your boss asked you to write a script that takes input but not through the user prompt ( the `input` command ). 6 | She wants you to use "command line arguments". With no time to spare you use the `sys` module to help you: 7 | 8 | 0. Find the starter script called `module4_lab1.py` in this GitHub repository. Copy and past it to a script in your workspace. 9 | 10 | 0. Run it as is and you should see similar output to this: 11 | 12 | ```bash 13 | $ python module4_lab1.py 14 | [ ARG-0 ]: module4_lab1.py 15 | ``` 16 | 17 | 0. Now run it again and add arbitrary arguments to the end of the command line: 18 | 19 | ```bash 20 | $ python module4_lab1.py --foo bar 1 2 3 baz 10,11 21 | ``` 22 | 23 | 0. How is `sys.argv` working? How does it parse the arguments? What is the delimiter ( the thing that it splits on )? 24 | 25 | 0. Can you modify `module4_lab1.py` and write a script that will take two command line arguments ( don't use `input` ) and outputs the sum? 26 | You'll need to think about converting arguments to the correct data types. You'll need to think about handling errors ( too few arguments, too many arguments, the wrong type of argument ). 27 | 28 | 29 | NOTE: you can imagine how much work this would be for a large script with many inputs data types. Next we'll look at a better solution 30 | -------------------------------------------------------------------------------- /Module9/lab2.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import csv 3 | 4 | class IrisReader: 5 | """ 6 | A kinda-sorta rule of thumb is that if you see a Python class 7 | with a single function and an initializer 8 | then it probably shouldn't be a class at all. 9 | Ignore that in this case 10 | """ 11 | 12 | def __init__(self, file_path): 13 | self.file_path = file_path 14 | 15 | def open(self): 16 | try: 17 | f = open(self.file_path) 18 | my_file_data = csv.reader(f) 19 | return my_file_data 20 | except IOError: 21 | print("File not found\n") 22 | return None 23 | 24 | 25 | class IrisStats: 26 | 27 | def __init__(self, file_path): 28 | self.sepal_length_column = 0 29 | self.petal_length_column = 2 30 | self.file_path = file_path 31 | self.iris_data = None # this is set in each stats function 32 | 33 | def get_avg_petal_length(self): 34 | # TODO1: finish this function 35 | self.iris_data = IrisReader(self.file_path).open() 36 | if self.iris_data is not None: 37 | pass 38 | 39 | def get_avg_sepal_length_per_class(self): 40 | # TODO2: finish this function 41 | self.iris_data = IrisReader(self.file_path).open() 42 | if self.iris_data is not None: 43 | pass 44 | 45 | import sys 46 | iris_stats = IrisStats(sys.argv[1]) 47 | print(iris_stats.get_avg_petal_length()) 48 | -------------------------------------------------------------------------------- /Module4/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module 4 Lab 2 2 | 3 | ## Instructions: 4 | 5 | Another programmer quit their job ( this happens a lot ). You are tasked with finishing a script that reads a file and dumps out descriptive statistics about the file numbers from certain columns. 6 | 7 | 0. Find the zipfile called `module4_lab2.zip` in this GitHub repository. Download and unzip it to your workspace. 8 | 9 | 0. Unzipped you should see a directory structure like this: 10 | 11 | ```bash 12 | module4_lab2/ 13 | ---- module4_lab2.py 14 | ---- data/ 15 | ---- ---- fahrenheit_monthly_readings.tsv 16 | ``` 17 | 18 | 0. Run the Python script `module4_lab2.py` as is and you should see similar output to this: 19 | 20 | ```bash 21 | $ python3 module4_lab2.py 22 | 23 | [ AVERAGE MAX TEMP ]: 0.0 24 | ``` 25 | 26 | 0. Now open the data file `fahrenheit_monthly_readings.tsv` and take a look at this file. Note the column names. Try to get sense for what they are telling you. 27 | 28 | 0. Find the comment `TODO 1` and read the instructions there. You'll need to open a file and read the rows and put it into a Python nested data structure of dictionaries and lists 29 | 30 | 0. If `TODO 1` was simple for you, please move on to `TODO 2` where you'll finish writing a function to calculate the max temperature from the column `MNTH_MAX` 31 | 32 | 0. If `TODO 2` was simple for you, please move on to `TODO 3` where you'll finish writing a function to calculate the mean temperature from the columns `MNTH_MIN` and `MNTH_MAX` 33 | -------------------------------------------------------------------------------- /Module5/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module 5 Lab 1 2 | 3 | ## Instructions: 4 | 5 | Another programmer quit their job ( this happens a lot ). You are tasked with finishing a script that reads a file and dumps out descriptive statistics about the file numbers from certain columns. 6 | 7 | 0. Find the zipfile called `module5_lab1.zip` in this GitHub repository. Download and unzip it to your workspace. 8 | 9 | 0. Unzipped you should see a directory structure like this: 10 | 11 | ```bash 12 | module5_lab1/ 13 | ---- module4_lab2.py 14 | ---- data/ 15 | ---- ---- fahrenheit_monthly_readings.tsv 16 | ``` 17 | 18 | 0. Run the Python script `module4_lab2.py` as is and you should see similar output to this: 19 | 20 | ```bash 21 | $ python3 module4_lab2.py 22 | 23 | [ AVERAGE MAX TEMP ]: 0.0 24 | ``` 25 | 26 | 0. Now open the data file `fahrenheit_monthly_readings.tsv` and take a look at this file. Note the column names. Try to get sense for what they are telling you. 27 | 28 | 0. Find the comment `TODO 1` and read the instructions there. You'll need to open a file and read the rows and put it into a Python nested data structure of dictionaries and lists. Try NOT to use the `csv` module. Do this with your ninja Python skills. 29 | 30 | 0. If `TODO 1` was simple for you, please move on to `TODO 2` where you'll finish writing a function to calculate the max temperature from the column `MNTH_MAX` 31 | 32 | 0. If `TODO 2` was simple for you, please move on to `TODO 3` where you'll finish writing a function to calculate the mean temperature from the columns `MNTH_MIN` and `MNTH_MAX` 33 | -------------------------------------------------------------------------------- /Module2/Module2_Lab2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Operations Lab" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Use string concatenation and user input to write a script that does the following:\n", 15 | "\n", 16 | "0. Create a script called `module2_lab2.py`\n", 17 | "0. Write some code that asks the user three arbitrary questions\n", 18 | "0. Write some code that takes the three question answers and `print`s the answers using `string.format` in the following style:\n", 19 | "\n", 20 | " ```bash\n", 21 | " $ python3 module2_lab2.py\n", 22 | " answer1 | answer2 | answer3\n", 23 | " ```\n", 24 | "\n", 25 | "0. Is there a way to do this without string concatenation? Hint, look into the string function `join`" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": null, 31 | "metadata": { 32 | "collapsed": true 33 | }, 34 | "outputs": [], 35 | "source": [] 36 | } 37 | ], 38 | "metadata": { 39 | "kernelspec": { 40 | "display_name": "Python 3", 41 | "language": "python", 42 | "name": "python3" 43 | }, 44 | "language_info": { 45 | "codemirror_mode": { 46 | "name": "ipython", 47 | "version": 3 48 | }, 49 | "file_extension": ".py", 50 | "mimetype": "text/x-python", 51 | "name": "python", 52 | "nbconvert_exporter": "python", 53 | "pygments_lexer": "ipython3", 54 | "version": "3.5.2" 55 | } 56 | }, 57 | "nbformat": 4, 58 | "nbformat_minor": 2 59 | } 60 | -------------------------------------------------------------------------------- /Module6/lab1/question4.py: -------------------------------------------------------------------------------- 1 | from data import movies, boxart 2 | 3 | # 4 | # Q7: 5 | # write a function 6 | # that combines 'movies' and 'boxart' Lists 7 | # into a new List of tuples where 8 | # tuple index 0 is the movie and tuple index 1 is the boxart for that movie 9 | # NOTE: `movies` and `boxart` in sorted so that each movie index matches 10 | # the boxart index 11 | # 12 | 13 | # TODO: interleaved = your_function() to make the test pass 14 | interleaved = [] 15 | print("[ INTERLEAVED ]: {}".format(interleaved)) 16 | assert interleaved == [ 17 | ( 18 | {'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 70111470, 'bookmark': [], 'rating': 4.0, 'title': 'Die Hard'}, 19 | {'height': 200, 'width': 200, 'url': 'http://cdn-0.nflximg.com/images/2891/DieHard.jpg'} 20 | ), 21 | ( 22 | {'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 654356453, 'bookmark': [{'id': 432534, 'time': 65876586}], 'rating': 5.0, 'title': 'Bad Boys'}, 23 | {'height': 200, 'width': 150, 'url': 'http://cdn-0.nflximg.com/images/2891/BadBoys.jpg'} 24 | ), 25 | ( 26 | {'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 65432445, 'bookmark': [], 'rating': 4.0, 'title': 'The Chamber'}, 27 | {'height': 200, 'width': 300, 'url': 'http://cdn-0.nflximg.com/images/2891/TheChamber.jpg'} 28 | ), 29 | ( 30 | {'uri': 'http://api.netflix.com/catalog/titles/movies/70111470', 'id': 675465, 'bookmark': [{'id': 432534, 'time': 65876587}], 'rating': 5.0, 'title': 'Fracture'}, 31 | {'height': 150, 'width': 425, 'url': 'http://cdn-0.nflximg.com/images/2891/Fracture.jpg'} 32 | ) 33 | ] 34 | -------------------------------------------------------------------------------- /Module9/lab1.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class Counter: 4 | 5 | def __init__(self, start_value=0): 6 | # counter always has to start at 0 7 | if start_value > 0: 8 | self._count = start_value 9 | else: 10 | self._count = 0 11 | 12 | def increment(self): 13 | self._count += 1 14 | return self._count 15 | 16 | def decrement(self): 17 | # counter cannot go below 0 18 | if self._count - 1 < 0: 19 | self._count = 0 20 | else: 21 | self._count -= 1 22 | return self._count 23 | 24 | 25 | class Namer: 26 | 27 | def __init__(self, name, age): 28 | self._name = name 29 | self._age = age 30 | 31 | def __str__(self): 32 | return "[ {} ]: name={} age={}".format( 33 | self.__class__, 34 | self._name, 35 | self._age, 36 | ) 37 | 38 | def say_my_name(self): 39 | # NOTE: this calls the __str__ override method 40 | print(self) 41 | 42 | def countdown(self): 43 | age_counter = Counter(start_value=self._age) 44 | next_age = age_counter._count 45 | while next_age > 0: 46 | print(next_age) 47 | next_age = age_counter.decrement() 48 | print("[ DONE ]") 49 | 50 | def show_me_my_data_guts(self): 51 | # 52 | # A Python class is just a fancy wrapper 53 | # around a dictionary. It has special ways to access 54 | # the dictionary internally from the class. So we can 55 | # do things such as this to get an internal view of the class 56 | # 57 | return "{}".format(self.__dict__) 58 | -------------------------------------------------------------------------------- /Module1/.ipynb_checkpoints/Lab1_unix-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Unix Basics\n", 8 | "\n", 9 | "The following exercise is designed to help you practice the unix commands that you'll need to work with python and many other programming languages. \n", 10 | "\n", 11 | "Try the following exercise on your own, or in a group; whatever way you work best. \n", 12 | "\n", 13 | "It's important that you get these basic operations down, so make sure to let us know if you have any questions. " 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "source": [ 22 | "- Create a directory called \"Mod1_Lab1\"\n", 23 | "- Change into your newly created directory\n", 24 | "- Copy a a file from the following URL into your Mod1_Lab1 directory: http://indeedeng.github.io/imhotep/files/nasa_19950801.tsv\n", 25 | "- Count the number of lines in the file\n", 26 | "- Look at the first few lines in the file\n", 27 | "- What command would you use to pull out the 3rd column of the file? \n", 28 | "- What command would you use to view the first five lines of the 5th column? " 29 | ] 30 | } 31 | ], 32 | "metadata": { 33 | "kernelspec": { 34 | "display_name": "Python 3", 35 | "language": "python", 36 | "name": "python3" 37 | }, 38 | "language_info": { 39 | "codemirror_mode": { 40 | "name": "ipython", 41 | "version": 3 42 | }, 43 | "file_extension": ".py", 44 | "mimetype": "text/x-python", 45 | "name": "python", 46 | "nbconvert_exporter": "python", 47 | "pygments_lexer": "ipython3", 48 | "version": "3.5.2" 49 | } 50 | }, 51 | "nbformat": 4, 52 | "nbformat_minor": 2 53 | } 54 | -------------------------------------------------------------------------------- /Module4/hw3_error_checking1.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | #Input two numbers 4 | num1 = int(input("Give me your first number: ")) 5 | num2 = int(input("Give me your second number: ")) 6 | 7 | #function to find max number in the inputed set 8 | def findmax(num1,num2): 9 | if num1 > num2: 10 | maximum = num1 11 | else: 12 | maximum = num2 13 | return(maximum) 14 | 15 | #function to find min number in the inputed set 16 | def findmin(num1,num2): 17 | if num1 < num2: 18 | minimum = num1 19 | else: 20 | minimum = num2 21 | return(minimum) 22 | 23 | #variable to create range between max and min in the inputed set 24 | #variable finds the difference between max and min number in the inputed set 25 | maxminrange = findmax(num1,num2)-findmin(num1,num2) 26 | 27 | #for loop that builds list of numbers between max and min number 28 | #enumerate is used to locate the number and position in the list 29 | #1 is added to the counter in order to adjust for the non-inclusive counting method 30 | #if statement and modulo is used to determine divisibility by 3 31 | mylist = [] 32 | for number,index in enumerate(range(maxminrange+1)): 33 | mylist.append(number+findmin(num1,num2)) 34 | if (number+findmin(num1,num2)) % 3 == 0: 35 | answer = "This number {} is divisible by 3.".format(number+findmin(num1,num2)) 36 | else: 37 | answer = "This number {} is NOT divisible by 3.".format(number+findmin(num1,num2)) 38 | print("This number {} is at index {}.".format(number+findmin(num1,num2), index),"\t", answer) 39 | 40 | '''There are many flaws in the current code: 41 | 1. User can input strings and it will return an error. 42 | 2. User can input float and it will return an error. 43 | 3. User can enter duplicate numbers, and even though it provides the corrent 44 | response, it should ask the user to provide distinct numbers. 45 | ''' 46 | -------------------------------------------------------------------------------- /Module3/module3_lab2_solution.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | 4 | def odd_or_even(i): 5 | if i%2 == 0: 6 | answer = 'even' 7 | else: 8 | answer = 'odd' 9 | return answer 10 | 11 | # 1 12 | print("\n[ SOLUTION 1 ]: simple for loop calling into `odd_or_even` function: \n") 13 | for i in range(10): 14 | answer = odd_or_even(i) 15 | print("{} is {}".format(i, answer)) 16 | 17 | # 2 18 | print("\n[ SOLUTION 2 ]: moving for loop into it's own function that calls another function: \n") 19 | def second_function(j): 20 | for i in range(j): 21 | answer = odd_or_even(i) 22 | print("{} is {}".format(i, answer)) 23 | 24 | second_function(10) # make sure to call it to execute it! 25 | 26 | # 3 27 | print("\n[ SOLUTION 3 ]: moving for loop into the same function as `odd_or_even`. NOTE: \ 28 | that this actually changes the meaning of the `odd_or_even` function. In the last two solutions \ 29 | `odd_or_even` told us whether a single integer argument was odd or even. Now it's telling us whether a \ 30 | range of integers are odd or even. Also compare this solution that only prints out the answer \ 31 | with the next more advanced solution that also returns the answers: \n") 32 | def odd_or_even_range(i): 33 | for i in range(i): 34 | if i%2 == 0: 35 | answer = 'even' 36 | else: 37 | answer = 'odd' 38 | print("{} is {}".format(i, answer)) 39 | 40 | odd_or_even_range(10) # make sure to call it to execute it! 41 | 42 | # 4 43 | print("\n[ SOLUTION 4 ]: this was the extra question on lab2. Here we do the same thing as solution 3 \ 44 | but return the answer(s) also: \n") 45 | def odd_or_even_range(i): 46 | answers = [] 47 | for i in range(i): 48 | if i%2 == 0: 49 | answer = 'even' 50 | else: 51 | answer = 'odd' 52 | print("{} is {}".format(i, answer)) 53 | answers.append(answer) 54 | return answers 55 | 56 | print(odd_or_even_range(10)) # make sure to call it to execute it! 57 | -------------------------------------------------------------------------------- /Module6/5_lightning_talks.md: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Lightning Talks" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "![](./pics/python_lightning.jpg?raw=true)" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": { 23 | "collapsed": true, 24 | "deletable": true, 25 | "editable": true 26 | }, 27 | "source": [ 28 | "## Start planning now! \n", 29 | "- 5 minute talk, no exceptions\n", 30 | "- Takes place during final class\n", 31 | "- Give a talk = 50 points\n", 32 | "- Review a talk = 5 points per review" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "## What do I talk about for five whole minutes? \n", 40 | "- Accomplish something using python\n", 41 | "- Show us it in action\n", 42 | "- Tell us how awesome it will make your life (What problems did it solve?)\n", 43 | "- Tell us about any difficulties you faced (How can you save your peers from similar suffering?)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Ideas\n", 51 | "- Automate a process\n", 52 | "- Try out a new python module\n", 53 | "- Create a twitter bot (this could be challenging)\n", 54 | "- Make a pretty graph in jupyter notebook" 55 | ] 56 | } 57 | ], 58 | "metadata": { 59 | "kernelspec": { 60 | "display_name": "Python 3", 61 | "language": "python", 62 | "name": "python3" 63 | }, 64 | "language_info": { 65 | "codemirror_mode": { 66 | "name": "ipython", 67 | "version": 3 68 | }, 69 | "file_extension": ".py", 70 | "mimetype": "text/x-python", 71 | "name": "python", 72 | "nbconvert_exporter": "python", 73 | "pygments_lexer": "ipython3", 74 | "version": "3.5.2" 75 | } 76 | }, 77 | "nbformat": 4, 78 | "nbformat_minor": 2 79 | } 80 | -------------------------------------------------------------------------------- /Module1/.ipynb_checkpoints/2_why_learn_unix_python-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Why Learn Unix and Python? " 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": { 13 | "collapsed": true 14 | }, 15 | "source": [ 16 | "## Unix\n", 17 | "\n", 18 | "![](./pics/linux.jpg?raw=true)\n", 19 | "\n", 20 | "If you're serious about becoming a programmer, it's essential to at least learn the basics of a command line interface, and Unix is the top choice. \n", 21 | "\n", 22 | "- Run commands and navigate directly from the command line\n", 23 | "- Memory efficiency\n", 24 | "- Directly run scripts without the need for extra software/interface\n", 25 | "- Most common server OS\n", 26 | "- Steep learning curve, but worth it" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## Python" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": { 39 | "collapsed": true 40 | }, 41 | "source": [ 42 | "![](./pics/monty_python.jpg?raw=true)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "- It's named after Monty Python... what more could you want? \n", 50 | "- Easy to read\n", 51 | "- Powerful\n", 52 | "- Frequently updated\n", 53 | "- Many powerful and useful modules\n", 54 | "- Easy, clear syntax\n", 55 | "- Platform agnostic" 56 | ] 57 | } 58 | ], 59 | "metadata": { 60 | "kernelspec": { 61 | "display_name": "Python 3", 62 | "language": "python", 63 | "name": "python3" 64 | }, 65 | "language_info": { 66 | "codemirror_mode": { 67 | "name": "ipython", 68 | "version": 3 69 | }, 70 | "file_extension": ".py", 71 | "mimetype": "text/x-python", 72 | "name": "python", 73 | "nbconvert_exporter": "python", 74 | "pygments_lexer": "ipython3", 75 | "version": "3.5.2" 76 | } 77 | }, 78 | "nbformat": 4, 79 | "nbformat_minor": 2 80 | } 81 | -------------------------------------------------------------------------------- /Module1/unix_commands.txt: -------------------------------------------------------------------------------- 1 | Following is a list of few important Linux/Unix commands: 2 | cat -- Display File Contents 3 | cd -- Changes Directory to dirname 4 | chgrp -- Change file group 5 | chmod -- Changing Permissions 6 | cp -- Copy source file into destination 7 | file -- Determine file type 8 | find -- Find files 9 | grep -- Search files for regular expressions. 10 | head -- Display first few lines of a file 11 | ln -- Create softlink on oldname 12 | ls -- Display information about file type. 13 | mkdir -- Create a new directory dirname 14 | more -- Display data in paginated form. 15 | mv -- Move (Rename) a oldname to newname. 16 | pwd -- Print current working directory. 17 | rm -- Remove (Delete) filename 18 | rmdir -- Delete an existing directory provided it is empty. 19 | tail -- Prints last few lines in a file. 20 | touch -- Update access and modification time of a file. 21 | -------------------------------------------------------------------------------- /Module1/Lab1_unix.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Unix Basics\n", 11 | "\n", 12 | "The following exercise is designed to help you practice the unix commands that you'll need to work with python and many other programming languages. \n", 13 | "\n", 14 | "Try the following exercise on your own, or in a group; whatever way you work best. \n", 15 | "\n", 16 | "It's important that you get these basic operations down, so make sure to let us know if you have any questions. " 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": { 22 | "collapsed": true, 23 | "deletable": true, 24 | "editable": true 25 | }, 26 | "source": [ 27 | "1. Create a directory called \"Mod1_Lab1\"\n", 28 | "2. Change into your newly created directory\n", 29 | "- Get the following file into your Mod1_Lab1 directory (download, copy and paste, whatever is easy): http://indeedeng.github.io/imhotep/files/nasa_19950801.tsv\n", 30 | "- Count the number of lines in the file\n", 31 | "- Look at the first few lines in the file\n", 32 | "- What command would you use to pull out the 3rd column of the file? \n", 33 | "- What command would you use to view the first five lines of the 5th column? " 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "** Hint: ** use the commands outlined [here](https://github.com/summerela/intro_programming_python/blob/master/Module1/unix_commands.txt)" 41 | ] 42 | } 43 | ], 44 | "metadata": { 45 | "kernelspec": { 46 | "display_name": "Python 3", 47 | "language": "python", 48 | "name": "python3" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": { 52 | "name": "ipython", 53 | "version": 3 54 | }, 55 | "file_extension": ".py", 56 | "mimetype": "text/x-python", 57 | "name": "python", 58 | "nbconvert_exporter": "python", 59 | "pygments_lexer": "ipython3", 60 | "version": "3.5.2" 61 | } 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 2 65 | } 66 | -------------------------------------------------------------------------------- /Module1/.ipynb_checkpoints/3_installing_stuff-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Installing all the things!\n", 8 | "\n", 9 | "![](./pics/install_all_things.jpg?raw=true)\n", 10 | "\n", 11 | "Try to follow along, but if you get stuck, don't worry, we'll have time during the lab to make sure you're setup and running. " 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": {}, 17 | "source": [ 18 | "## Setting up a Unix Environment\n", 19 | "### Terminal in Mac\n", 20 | "Because OSx is based off of unix, accessing the command line from a mac is super easy; just hit command + spacebar and search for \"terminal\". \n", 21 | "\n", 22 | "### GitBash in Windows\n", 23 | "Since Windows is based off of DOS instead of UNIX, we'll use Git Bash to keep things from getting too complicated. " 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "## Install Git\n", 31 | "\n", 32 | "- Download the most recent windows or mac version from: \n", 33 | "https://git-scm.com/downloads" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Install Python3\n", 41 | "- Download the most recent version of python3 for mac or windows from: https://www.python.org/downloads/" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "## Installing Sublime Text\n", 49 | "- Download the most recent version of sublime text version 2 for mac or windows from:\n", 50 | "http://www.sublimetext.com/2" 51 | ] 52 | } 53 | ], 54 | "metadata": { 55 | "kernelspec": { 56 | "display_name": "Python 3", 57 | "language": "python", 58 | "name": "python3" 59 | }, 60 | "language_info": { 61 | "codemirror_mode": { 62 | "name": "ipython", 63 | "version": 3 64 | }, 65 | "file_extension": ".py", 66 | "mimetype": "text/x-python", 67 | "name": "python", 68 | "nbconvert_exporter": "python", 69 | "pygments_lexer": "ipython3", 70 | "version": "3.5.2" 71 | } 72 | }, 73 | "nbformat": 4, 74 | "nbformat_minor": 2 75 | } 76 | -------------------------------------------------------------------------------- /Module7/lab1/Lab1.md: -------------------------------------------------------------------------------- 1 | # Module 7 Lab 1 2 | 3 | A very-light introduction to version control. 4 | For more see [this tutorial](http://product.hubspot.com/blog/git-and-github-tutorial-for-beginners) 5 | 6 | ## Instructions: 7 | 8 | 0. Install `git` for your operating system. 9 | Read about [how to do it here](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) 10 | 11 | 0. Create a free `GitHub` account over [here](https://github.com/). 12 | (Accounts are free for public repositories, but there's a charge for private repositories past a certain number) 13 | 14 | 0. After you signup you'll receive an email. Hold onto that, it's important. You should see a screen like this: 15 | ![splash_screen](1_aftersignup.png) 16 | 17 | 0. Click the "Start Project" button to the right: 18 | ![click_startproject](2_click_start_project.png) 19 | 20 | 0. Go to your email and click on the verification link like this page tells us to: 21 | ![3_verify_by_email](3_verify_by_email.png) 22 | 23 | 0. Then go back to your `dashboard` -- link is at the top right or just go to `https://github.com`. Click on the plus ( + ) sign 24 | at the top right and click "New Repository": 25 | ![4_from_dashboard_click_new_repository](4_from_dashboard_click_new_repository.png) 26 | 27 | 0. Fill out the new respository form with your information. When you are done click "Create Repository": 28 | ![5_fill_out_the_repository_form](5_fill_out_the_repository_form.png) 29 | 30 | 0. Welcome to your new repository dashboard view!: 31 | ![6_see_your_new_repo](6_see_your_new_repo.png) 32 | 33 | 0. Click the green button called "Clone Repository" and when the modal pops open copy the value there: 34 | ![7_click_clone](7_click_clone.png) 35 | 36 | 0. Then go to an existing workspace ( it's better if you create a new folder maybe ) and `clone` the remote repository with 37 | this command `git clone `: 38 | ![8_cli_clone](8_cli_clone.png) 39 | 40 | 0. Then the magic happens! Files are downloaded from the interwebs. Let's see what's here with some `ls` command stuff ( `dir` on Windows ): 41 | ![9_see_stuff](9_see_stuff.png) 42 | 43 | 0. Whoohoo! We've download files from the web. We can see the `README.md` from our repository. Highfive! Before we move on, go to `https://github.com/settings/admin` and create 44 | a password and click "Update Password": 45 | ![10_change_your_password](10_change_your_password.png) 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Module7/1_git.md: -------------------------------------------------------------------------------- 1 | # Git Version Control Software 2 | 3 | ## Version Control 4 | ![Github](https://github.com/summerela/intro_programming_python/blob/master/Module7/github.jpg) 5 | 6 | - Track who changed what 7 | - Roll back to previous version 8 | - Roll back mistakes 9 | - Keep your project in a safe, online location 10 | 11 | ## Git command line basics (windows users, use git bash!) 12 | - Git = version control system 13 | - GitHub = social code repository (place to store your code) 14 | - Your computer = local repository 15 | - Github servers = remote repository 16 | 17 | **The following outline assumes you have already installed git and 18 | setup a github account. We will do that portion in the lab** 19 | 20 | ### Clone an Existing Repo 21 | If the repository already exists, you can just copy it right onto your 22 | computer. 23 | 24 | git clone https://github.com/summerela/intro_programming_python 25 | 26 | - This copy becomes your own 27 | - Add/edit/delete 28 | - Create a request to add your changes to the original branch (they 29 | don't have to accept) 30 | 31 | ### Create a new repo 32 | The easiest way to do this is to first create a blank repo on 33 | github.com and then pull it to your computer 34 | 35 | ### Pulling down changes to a repo 36 | Before you start working on a git repository locally, good practice is 37 | to pull down all the recent changes from github. 38 | 39 | From your local computer: 40 | 41 | cd intro_programming_python 42 | git pull intro_programming_python 43 | 44 | ### Adding a new file to the repository 45 | Your file will never be pushed to the remote repo on github.com until 46 | you tell git to start tracking the file by using "git add": 47 | 48 | git add new_file.txt 49 | 50 | ### Commiting changes to a file 51 | Any time you do something to a file that you want to be pushed up to 52 | the remote repo, you must commit those changes and use the -m argument 53 | to add a commit message detailing what you've done: 54 | 55 | git commit new_file.txt -m "added new_file.txt. remind summer to 56 | show you where these message show up on github" 57 | 58 | ### Check the status of your repo 59 | See what files have been changed, and what you need to commit before a 60 | push/pull. 61 | 62 | git status 63 | 64 | ### View the differences between local and remote files 65 | Determine what you've changed in a file and decide if you want to keep 66 | those changes. 67 | 68 | git diff 69 | 70 | ### View the log of recent commits 71 | 72 | git log 73 | -------------------------------------------------------------------------------- /Module1/8_module1_lab2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Create and Run a Python Script" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "The following exercise should be done from your command prompt or terminal. " 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "#### Use the following command to create a python file" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": { 28 | "collapsed": true 29 | }, 30 | "outputs": [], 31 | "source": [ 32 | "echo \"print('Hello World')\" > test.py" 33 | ] 34 | }, 35 | { 36 | "cell_type": "markdown", 37 | "metadata": {}, 38 | "source": [ 39 | "#### Let's view the contents of this new python script" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 3, 45 | "metadata": { 46 | "collapsed": false 47 | }, 48 | "outputs": [ 49 | { 50 | "name": "stdout", 51 | "output_type": "stream", 52 | "text": [ 53 | "print('Hello World')\r\n" 54 | ] 55 | } 56 | ], 57 | "source": [ 58 | "cat test.py" 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "#### Now let's run this script and see what it does!" 66 | ] 67 | }, 68 | { 69 | "cell_type": "markdown", 70 | "metadata": {}, 71 | "source": [ 72 | "python3 test.py" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": { 78 | "collapsed": true, 79 | "deletable": true, 80 | "editable": true 81 | }, 82 | "source": [ 83 | "### Congratulations, you just created and ran a python script!" 84 | ] 85 | } 86 | ], 87 | "metadata": { 88 | "kernelspec": { 89 | "display_name": "Python 3", 90 | "language": "python", 91 | "name": "python3" 92 | }, 93 | "language_info": { 94 | "codemirror_mode": { 95 | "name": "ipython", 96 | "version": 3 97 | }, 98 | "file_extension": ".py", 99 | "mimetype": "text/x-python", 100 | "name": "python", 101 | "nbconvert_exporter": "python", 102 | "pygments_lexer": "ipython3", 103 | "version": "3.5.2" 104 | } 105 | }, 106 | "nbformat": 4, 107 | "nbformat_minor": 2 108 | } 109 | -------------------------------------------------------------------------------- /Module8/hw7_answer.py: -------------------------------------------------------------------------------- 1 | from sortedcontainers import SortedDict 2 | 3 | def print_menu(): 4 | print('1. Print Users') 5 | print('2. Add a User') 6 | print('3. Remove a User') 7 | print('4. Lookup a User') 8 | print('5. Quit') 9 | print() 10 | 11 | # Create dictionary with key = Names, value = user_name 12 | usernames = SortedDict() 13 | usernames['Summer'] = 'summerela' 14 | usernames['William'] = 'GoofyFish' 15 | usernames['Steven'] = 'LoLCat' 16 | usernames['Zara'] = 'zanyZara' 17 | usernames['Renato'] = 'songDude' 18 | 19 | # setup counter to store menu choice 20 | menu_choice = 0 21 | 22 | #display your menu 23 | print_menu() 24 | 25 | # as long as the menu choice isn't "quit" get user options 26 | while menu_choice != 5: 27 | # get menu choice from user 28 | menu_choice = int(input("Type in a number (1-5): ")) 29 | 30 | # view current entries 31 | if menu_choice == 1: 32 | print("Current Users:") 33 | for x,y in usernames.items(): 34 | print("Name: {} \tUser Name: {} \n".format(x,y)) 35 | 36 | # add an entry 37 | elif menu_choice == 2: 38 | print("Add User") 39 | name = input("Name: ") 40 | username = input("Username: ") 41 | usernames[name] = username 42 | 43 | # remove an entry 44 | elif menu_choice == 3: 45 | # what do i do here? 46 | print("Remove User") 47 | # get the name of the user they want to delete 48 | input_name = input("Name: ") 49 | # check if input name in dictionary 50 | if input_name in usernames: 51 | del usernames[input_name] 52 | 53 | # view user name 54 | elif menu_choice == 4: 55 | print("Lookup User") 56 | name = input("Name or username: ") 57 | if name in usernames: 58 | print(usernames[name]) 59 | else: 60 | print("User not found.") 61 | 62 | # # view user name 63 | # elif menu_choice == 4: 64 | # print("Lookup User") 65 | # name = input("Name or username: ") 66 | # for key, value in usernames.items(): 67 | # if (name == key): 68 | # print(usernames[name]) 69 | # if (name == value): 70 | # print([item[0] for item in usernames.items() if item[1] == name]) 71 | # else: 72 | # print("User not found.") 73 | 74 | # is user enters something strange, show them the menu 75 | else: 76 | print_menu() -------------------------------------------------------------------------------- /Module2/Module2_Lab1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Formatting Lab " 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Someone quit their job after writing a broken script and we have to fix it to output data properly.\n", 15 | "\n", 16 | "0. Download and try to run the script `module2_lab1.py`. Note that it doesn't run correctly:\n", 17 | "\n", 18 | " ```bash\n", 19 | " $ python3 module2_lab1.py\n", 20 | " File \"module2_lab1.py\", line 8\n", 21 | " a table of rows where the first row\n", 22 | " ^\n", 23 | " SyntaxError: invalid syntax\n", 24 | " ```\n", 25 | "\n", 26 | "0. Find and fix the 3 bad comment sections. Rerun the script when you feel like the problem is solved.\n", 27 | "When it runs successfully you'll see output like this:\n", 28 | "\n", 29 | " ```bash\n", 30 | " $ python3 module2_lab1.py\n", 31 | " FirstName|LastName|City|Zipcode\n", 32 | " Greg|Corradini|Minneapolis|75432\n", 33 | " Summer|Rae|Seattle|98103\n", 34 | " ```\n", 35 | "\n", 36 | "0. Unfortunately, this script is supposed to output a slightly nicer formatted table structure. How might you modify the\n", 37 | "last part of the script to produce output that looks sorta like one of the options below?\n", 38 | "\n", 39 | " ```bash\n", 40 | " |FirstName |LastName |City |Zipcode |\n", 41 | " |Greg |Corradini |Minneapolis |75432 |\n", 42 | " |Summer |Rae |Seattle |98103 |\n", 43 | " ```\n", 44 | "\n", 45 | " ```bash\n", 46 | " |FirstName |LastName |City |Zipcode |\n", 47 | " |Greg |Corradini |Minneapolis |75432 |\n", 48 | " |Summer |Rae |Seattle |98103 |\n", 49 | " ```" 50 | ] 51 | } 52 | ], 53 | "metadata": { 54 | "kernelspec": { 55 | "display_name": "Python 3", 56 | "language": "python", 57 | "name": "python3" 58 | }, 59 | "language_info": { 60 | "codemirror_mode": { 61 | "name": "ipython", 62 | "version": 3 63 | }, 64 | "file_extension": ".py", 65 | "mimetype": "text/x-python", 66 | "name": "python", 67 | "nbconvert_exporter": "python", 68 | "pygments_lexer": "ipython3", 69 | "version": "3.5.2" 70 | } 71 | }, 72 | "nbformat": 4, 73 | "nbformat_minor": 2 74 | } 75 | -------------------------------------------------------------------------------- /Module6/5_lightning_talks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Lightning Talks" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": true, 17 | "deletable": true, 18 | "editable": true 19 | }, 20 | "source": [ 21 | "## Need Extra Credit? Start planning now! \n", 22 | "- 5 minute talk, no exceptions\n", 23 | "- Takes place during final class\n", 24 | "- Give a talk = 50 points\n", 25 | "- Review a talk = 5 points per review" 26 | ] 27 | }, 28 | { 29 | "cell_type": "markdown", 30 | "metadata": {}, 31 | "source": [ 32 | "## Grading Criteria\n", 33 | "- Talk is well timed (5 minutes, no more, no less) = 10 points\n", 34 | "- Code contains at least three python functions = 10 points\n", 35 | "- Code takes at least one user argument as a parameter = 10 points\n", 36 | "- Code does what it's supposed to do = 10 points\n", 37 | "- Script successfully uploaded to github = 10 points\n", 38 | "\n", 39 | "Why yes, yes you can use your final project for this talk!" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "deletable": true, 46 | "editable": true 47 | }, 48 | "source": [ 49 | "## What do I talk about for five whole minutes? \n", 50 | "- Accomplish something using python\n", 51 | "- Show us it in action\n", 52 | "- Tell us how awesome it will make your life (What problems did it solve?)\n", 53 | "- Tell us about any difficulties you faced (How can you save your peers from similar suffering?)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "deletable": true, 60 | "editable": true 61 | }, 62 | "source": [ 63 | "## Ideas\n", 64 | "- Automate a process\n", 65 | "- Try out a new python module\n", 66 | "- Create a twitter bot (this could be challenging)\n", 67 | "- Make a pretty graph in jupyter notebook" 68 | ] 69 | } 70 | ], 71 | "metadata": { 72 | "kernelspec": { 73 | "display_name": "Python 3", 74 | "language": "python", 75 | "name": "python3" 76 | }, 77 | "language_info": { 78 | "codemirror_mode": { 79 | "name": "ipython", 80 | "version": 3 81 | }, 82 | "file_extension": ".py", 83 | "mimetype": "text/x-python", 84 | "name": "python", 85 | "nbconvert_exporter": "python", 86 | "pygments_lexer": "ipython3", 87 | "version": "3.5.2" 88 | } 89 | }, 90 | "nbformat": 4, 91 | "nbformat_minor": 2 92 | } 93 | -------------------------------------------------------------------------------- /Module4/module4_lab2_min_max_med_mean.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/local/src python3 3 | 4 | import os, sys 5 | ABSOLUTE_TSV_PATH=os.path.join( os.path.split(os.path.abspath(__name__))[0], 'data', 'fahrenheit_monthly_readings.tsv' ) 6 | 7 | def get_max_width(table, padding=2): 8 | #calculate the max width of the table cell 9 | max_width = 0 10 | for row in table[1:]: # skip the header row: 11 | new_max = max([len(value) for value in row]) + padding 12 | # only set the new max if it's actually greater 13 | if new_max > max_width: 14 | max_width = new_max 15 | return max_width 16 | 17 | def print_table(table): 18 | max_width = get_max_width(table) 19 | for row in table: 20 | print(*[str(i).center(max_width) for i in row], sep='|') 21 | 22 | def calc_max_temp_average(table): 23 | max_temps = [] 24 | for row in table[1:]: # skip the header row: 25 | max_column = len(row) - 1 26 | max_temps.append(int(row[max_column])) 27 | 28 | print("[ AVERAGE MAX TEMP ]: {}".format(sum(max_temps)/len(max_temps))) 29 | 30 | def calc_min_temp(table): 31 | min = None 32 | for row in table[1:]: # skip the header row: 33 | min_column = len(row) - 2 34 | new_min = int(row[min_column]) 35 | 36 | if min is None: # indicator to set first min value 37 | min = new_min 38 | 39 | if new_min < min: 40 | min = new_min 41 | 42 | print("[ MIN TEMP ]: {}".format(min)) 43 | 44 | def calc_max_temp(table): 45 | max_temps = [] 46 | for row in table[1:]: # skip the header row: 47 | max_column = len(row) - 1 48 | max_temps.append( int(row[max_column]) ) 49 | 50 | print("[ MAX TEMP ]: {}".format(max(max_temps))) 51 | 52 | def calc_median_temp(table): 53 | import statistics 54 | all_temps = [] 55 | for row in table[1:]: # skip the header row: 56 | min_column = len(row) - 2 57 | max_column = len(row) - 1 58 | all_temps = all_temps + [ int(row[min_column]), int(row[max_column]) ] 59 | 60 | print("[ MEDIAN OF ALL TEMPS ]: {}".format(statistics.median(all_temps))) 61 | 62 | in_memory_table = [] 63 | with open( ABSOLUTE_TSV_PATH, 'r' ) as file_sock: 64 | for line in file_sock: 65 | line = line.strip() # strip off extraneous whitespace chars such as newline or tabs 66 | row = line.split('\t') 67 | in_memory_table.append(row) 68 | 69 | # RUN THIS THANG 70 | print_table(in_memory_table) 71 | calc_max_temp_average(in_memory_table) 72 | calc_max_temp(in_memory_table) 73 | calc_min_temp(in_memory_table) 74 | calc_median_temp(in_memory_table) 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /Module7/4_final_projects.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Final Projects" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "collapsed": true, 17 | "deletable": true, 18 | "editable": true 19 | }, 20 | "source": [ 21 | "- Due by the end of Week 10\n", 22 | "- This is your homework for Week 10, not an additional assignment\n", 23 | "- Worth 200 points\n", 24 | "- You can use this for your extra credit lightning talks\n" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "#### What is it? \n", 32 | "You create a script. \n", 33 | "\n", 34 | "Make this as awesome, cheesy, simple, difficult as you want! But it will be graded as follows: " 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "#### Grading Criteria: \n", 42 | "\n", 43 | "#### Must: \n", 44 | "- Include a function that takes at least two user arguments from the command line\n", 45 | "- Contain at least one if/else statement\n", 46 | "- Perform a caclulation on a list\n", 47 | "- Use at least one dictionary\n", 48 | "- Have one try/except clause for every function\n", 49 | "- Output something (write) to a file, using string formatting\n", 50 | "- Must include docstrings telling us how to run your script. \n", 51 | "\n", 52 | "#### Options: \n", 53 | "- Either create a class to contain the related functions OR output a simple graph \n", 54 | "\n", 55 | "#### To Turn in: \n", 56 | "Upload your final python script or jupyter notebook to Github, turn in the link on Canvas\n" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## What you get out of this is up to you; you can make this as simple or awesome as you want! " 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": { 70 | "collapsed": true 71 | }, 72 | "outputs": [], 73 | "source": [] 74 | } 75 | ], 76 | "metadata": { 77 | "kernelspec": { 78 | "display_name": "Python 3", 79 | "language": "python", 80 | "name": "python3" 81 | }, 82 | "language_info": { 83 | "codemirror_mode": { 84 | "name": "ipython", 85 | "version": 3 86 | }, 87 | "file_extension": ".py", 88 | "mimetype": "text/x-python", 89 | "name": "python", 90 | "nbconvert_exporter": "python", 91 | "pygments_lexer": "ipython3", 92 | "version": "3.5.2" 93 | } 94 | }, 95 | "nbformat": 4, 96 | "nbformat_minor": 2 97 | } 98 | -------------------------------------------------------------------------------- /Module4/hw3_error_checking3.py: -------------------------------------------------------------------------------- 1 | '''Create a script called hw3.py 2 | Write a function that takes a minimum and maximum number as an argument. - check 3 | Your function should print out the following for each number in the range: 4 | This number {} is at index {} in the list. - check 5 | If a number is divisible by 3, print the following sentence instead (use string formatting): - check 6 | "The number {} is divisible by 3 and at index {} in the list." - check 7 | Add a docstring to the beginning of your script providing your thoughts on how a user -check 8 | might break your function (fix them if you know how!) 9 | 10 | 11 | HOW CAN IT BE BROKE? 12 | I don't think it can be broken. Though it took many iterations 13 | to get to this point. At one point, a Max number that was actually 14 | lower than the Min number would've broken it. 15 | I've played with a few different versions of multiple entries 16 | and so far it's working.''' 17 | 18 | 19 | minnum = int(input("Please type a low number:")) 20 | 21 | #Use a function to get (and ensure) a max number 22 | 23 | def ensure_bignum(minnum): 24 | bignum = int(input("Please type a big number: ")) 25 | while bignum <= minnum: 26 | print("Sorry, it must be bigger than your first number.") 27 | bignum = int(input("Please type a big number: ")) 28 | return bignum 29 | 30 | maxnum = ensure_bignum(minnum) 31 | 32 | 33 | 34 | #Calculate the length of our list by subtracting the large from small number. 35 | length = maxnum - minnum 36 | # testingline print(length) 37 | 38 | 39 | 40 | #This section defines the list name and 41 | # then builds the list. It does this by using the 'append' function 42 | # to build it 1 by 1 until we get to the Max num. 43 | 44 | lowtohighlist = [minnum,maxnum] 45 | # testingline print(lowtohighlist) 46 | nextnum=minnum+1 47 | # testingline print(nextnum) 48 | lowtohighlist.append(minnum) 49 | # testingline print(lowtohighlist) 50 | 51 | 52 | 53 | 54 | 55 | #create the list which starts with the "low number" and tops out at the "high number" 56 | 57 | newlist=[minnum] 58 | for counter in range(length): 59 | #testingline print("counter=",counter, "length=",length) 60 | lastnumberinlist=newlist[len(newlist)-1] 61 | nextnumberinlist = lastnumberinlist + 1 62 | #testingline print("lastnumberinlist=",lastnumberinlist, "nextnumber is=", nextnumberinlist) 63 | newlist.append(nextnumberinlist) 64 | #testingline print(newlist) 65 | 66 | print("This is your list: ",newlist) 67 | 68 | 69 | 70 | #this starts to do the real work. 71 | #it walks through the list and does that actual analysis and printing. 72 | 73 | for position in range(length+1): 74 | walkthelist = newlist[position] 75 | #testingline print("\twalkthelist=", walkthelist) 76 | if walkthelist%3==0: 77 | print("DIVISIBLE BY 3 WARNING....Number {} at position {} is divisble by 3".format(walkthelist,position)) 78 | else: 79 | print("Number {} is at position {} in the list".format(walkthelist, position)) 80 | 81 | -------------------------------------------------------------------------------- /Module6/3_more_user_args.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Gathering (more) User Input" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Interactive Programs" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 3, 20 | "metadata": { 21 | "collapsed": false 22 | }, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "Input a number: 12\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "user_number1 = int(input(\"Input a number: \"))" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": 4, 39 | "metadata": { 40 | "collapsed": false 41 | }, 42 | "outputs": [ 43 | { 44 | "name": "stdout", 45 | "output_type": "stream", 46 | "text": [ 47 | "Input another number: 24\n" 48 | ] 49 | } 50 | ], 51 | "source": [ 52 | "user_number2 = int(input(\"Input another number: \"))" 53 | ] 54 | }, 55 | { 56 | "cell_type": "markdown", 57 | "metadata": {}, 58 | "source": [ 59 | "## Running scripts from the command line with sys\n", 60 | "- great for simple user arguments such as file names\n", 61 | "- does no parsing of arguments\n", 62 | "- positional arguments, no keywords" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": { 69 | "collapsed": true 70 | }, 71 | "outputs": [], 72 | "source": [ 73 | "python3 my_script.py arg1 arg2 arg3" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": null, 79 | "metadata": { 80 | "collapsed": true 81 | }, 82 | "outputs": [], 83 | "source": [ 84 | "import sys\n", 85 | "\n", 86 | "#sys.argv[0] = python3\n", 87 | "\n", 88 | "first_arg = sys.argv[1]\n", 89 | "second_arg = sys.argv[2]\n", 90 | "third_arg = sys.argv[3]\n", 91 | "\n", 92 | "print(first_arg)" 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "## More Complicated User Arguments with ArgParse\n", 100 | "- keyword arguments\n", 101 | "- argument parsing\n", 102 | "- slightly complicated setup\n", 103 | "- Don't need for this class\n", 104 | "\n", 105 | "[More info here!](https://dmorgan.info/posts/argparse-intro/)" 106 | ] 107 | } 108 | ], 109 | "metadata": { 110 | "kernelspec": { 111 | "display_name": "Python 3", 112 | "language": "python", 113 | "name": "python3" 114 | }, 115 | "language_info": { 116 | "codemirror_mode": { 117 | "name": "ipython", 118 | "version": 3 119 | }, 120 | "file_extension": ".py", 121 | "mimetype": "text/x-python", 122 | "name": "python", 123 | "nbconvert_exporter": "python", 124 | "pygments_lexer": "ipython3", 125 | "version": "3.5.2" 126 | } 127 | }, 128 | "nbformat": 4, 129 | "nbformat_minor": 2 130 | } 131 | -------------------------------------------------------------------------------- /Module7/iris_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import csv 5 | import sys 6 | 7 | my_file = sys.argv[1] 8 | 9 | def read_in_csv(file_path): 10 | f = open(file_path) 11 | my_file = csv.reader(f) 12 | return my_file 13 | 14 | def get_column_unique(in_file, col_number): 15 | col_list = [] 16 | my_file = read_in_csv(in_file) 17 | for row in my_file: 18 | col_list.append(row[col_number]) 19 | unique_vals = set(col_list) 20 | unique_length = len(unique_vals) 21 | return unique_length 22 | 23 | def count_things(in_file, col_number): 24 | my_dict = {} 25 | my_file = read_in_csv(in_file) 26 | 27 | # loop through dictionary to track name and count 28 | for row in my_file: 29 | key_name = row[col_number] 30 | 31 | # for every row, check if the class_name is in the dictionary 32 | if key_name in my_dict: 33 | my_dict[key_name] = my_dict[key_name] + 1 34 | 35 | # if not, add it, and set the count to 1 36 | else: 37 | my_dict[key_name] = 1 38 | 39 | return my_dict 40 | 41 | # calc average of a column 42 | def average_col(in_file, col): 43 | my_file = read_in_csv(in_file) 44 | vals_to_avg = [] 45 | for row in my_file: 46 | vals_to_avg.append(float(row[col])) 47 | col_sum= sum(vals_to_avg) 48 | length = len(vals_to_avg) 49 | avg = col_sum/length 50 | return avg 51 | 52 | # calc averge of specific class 53 | def calc_class_avg(infile, class_col, class_name): 54 | my_file = read_in_csv(infile) 55 | vals_to_avg = [] 56 | 57 | # loop through dictionary to track name and count 58 | for row in my_file: 59 | if row[class_col] == class_name: 60 | vals_to_avg.append(float(row[0])) 61 | val_sum =sum(vals_to_avg) 62 | val_length = int(len(vals_to_avg)) 63 | class_avg = val_sum/val_length 64 | return class_avg 65 | 66 | # get petal length for a particular class 67 | # feed it file 68 | # petal length column number 69 | # class column number 70 | 71 | def calc_class_avg(infile, avg_col, class_col, class_name): 72 | 73 | petal_length_list = [] 74 | 75 | # read in the file 76 | my_file = read_in_csv(infile) 77 | 78 | # if class col is equal to the class name 79 | for row in file: 80 | if row[class_col] == class_name: 81 | petal_length_list.append(row[avg_col]) 82 | 83 | # get the petal length 84 | 85 | # sum petal 86 | 87 | # divide that by how many observations 88 | 89 | 90 | # have the user specify input file 91 | in_file = sys.argv[1] 92 | 93 | unique_vals = get_column_unique(my_file, 4) 94 | count_classes = count_things(my_file, 4) 95 | 96 | #calculate overall average sepal length 97 | sepal_avg = average_col(in_file,0) 98 | 99 | 100 | # calculate average sepal length by class name 101 | sepal_class_length = calc_class_avg(sys.argv[1], 4, "iris-setosa") 102 | 103 | print("There are {} unique classes in this file.".format(unique_vals)) 104 | print(count_classes) 105 | print(sepal_avg) 106 | print(sepal_class_length) 107 | -------------------------------------------------------------------------------- /Module1/7_Troubleshooting.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Troubleshooting: When Stuff Goes Wrong" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Use Print Statements" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "collapsed": true 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "def long_function(var1, var2):\n", 26 | " new_var = var1 + var2\n", 27 | " return(new_var)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "collapsed": true 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "def long_function(var1, var2):\n", 39 | " new_var = var1 + var2\n", 40 | " # return(new_var)\n", 41 | " print(var1)\n", 42 | " print(var2)\n", 43 | " print(new_var)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Break things down" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": { 57 | "collapsed": true 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "def long_function(var1, var2):\n", 62 | " new_var = var1 + var2\n", 63 | " other_var = new_var * 10\n", 64 | " yet_another = other_var + 3000\n", 65 | " return(yet_another)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": { 72 | "collapsed": true 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "def long_function(var1, var2):\n", 77 | " new_var = var1 + var2\n", 78 | " print(new_var)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## Google and StackExchange/StackOverflow" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "### Google\n", 93 | "Improve your google search by adding \"python\" and the name of the operation you are trying to do to your search string: \n", 94 | "- python add two variables\n", 95 | "- python concatenate strings\n", 96 | "- python string formatting\n", 97 | "- etc\n", 98 | "\n", 99 | "### StackExchange/Overflow\n", 100 | "This is a great resource for all of your programming questions. Just make sure to search thoroughly first to see if the question has already been answered, or else you will be flamed!\n", 101 | "https://stackoverflow.com/\n", 102 | "\n", 103 | "- Give your post a precise title\n", 104 | "- Add relevent tags such as \"python\", \"multiplication\"\n", 105 | "- Give details about your input, desired output and the steps you've already tried" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": { 112 | "collapsed": true 113 | }, 114 | "outputs": [], 115 | "source": [] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.5.2" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 2 139 | } 140 | -------------------------------------------------------------------------------- /Module1/.ipynb_checkpoints/7_Troubleshooting-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Troubleshooting: When Stuff Goes Wrong" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Use Print Statements" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "collapsed": true 22 | }, 23 | "outputs": [], 24 | "source": [ 25 | "def long_function(var1, var2):\n", 26 | " new_var = var1 + var2\n", 27 | " return(new_var)" 28 | ] 29 | }, 30 | { 31 | "cell_type": "code", 32 | "execution_count": null, 33 | "metadata": { 34 | "collapsed": true 35 | }, 36 | "outputs": [], 37 | "source": [ 38 | "def long_function(var1, var2):\n", 39 | " new_var = var1 + var2\n", 40 | " # return(new_var)\n", 41 | " print(var1)\n", 42 | " print(var2)\n", 43 | " print(new_var)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Break things down" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": { 57 | "collapsed": true 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "def long_function(var1, var2):\n", 62 | " new_var = var1 + var2\n", 63 | " other_var = new_var * 10\n", 64 | " yet_another = other_var + 3000\n", 65 | " return(yet_another)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": { 72 | "collapsed": true 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "def long_function(var1, var2):\n", 77 | " new_var = var1 + var2\n", 78 | " print(new_var)" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": {}, 84 | "source": [ 85 | "## Google and StackExchange/StackOverflow" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "### Google\n", 93 | "Improve your google search by adding \"python\" and the name of the operation you are trying to do to your search string: \n", 94 | "- python add two variables\n", 95 | "- python concatenate strings\n", 96 | "- python string formatting\n", 97 | "- etc\n", 98 | "\n", 99 | "### StackExchange/Overflow\n", 100 | "This is a great resource for all of your programming questions. Just make sure to search thoroughly first to see if the question has already been answered, or else you will be flamed!\n", 101 | "https://stackoverflow.com/\n", 102 | "\n", 103 | "- Give your post a precise title\n", 104 | "- Add relevent tags such as \"python\", \"multiplication\"\n", 105 | "- Give details about your input, desired output and the steps you've already tried" 106 | ] 107 | }, 108 | { 109 | "cell_type": "code", 110 | "execution_count": null, 111 | "metadata": { 112 | "collapsed": true 113 | }, 114 | "outputs": [], 115 | "source": [] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.5.2" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 2 139 | } 140 | -------------------------------------------------------------------------------- /Module5/HW4_review.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Homework 4 Review\n", 11 | "Write a function that only prints out information for airports in Russia or Australia" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "deletable": true, 18 | "editable": true 19 | }, 20 | "source": [ 21 | "## Quick Answer" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": null, 27 | "metadata": { 28 | "collapsed": true, 29 | "deletable": true, 30 | "editable": true 31 | }, 32 | "outputs": [], 33 | "source": [ 34 | "import csv\n", 35 | "\n", 36 | "f = open('airports.dat', encoding='utf8') \n", 37 | "reader = csv.reader(f, delimiter=',') \n", 38 | "\n", 39 | "for row in reader:\n", 40 | " airport = row[3] \n", 41 | " if airport == 'Russia' or airport == 'Australia': \n", 42 | " print('Row #' + str(reader.line_num) + ' ' + str(row))" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": { 48 | "deletable": true, 49 | "editable": true 50 | }, 51 | "source": [ 52 | "## Turn it into a function" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 27, 58 | "metadata": { 59 | "collapsed": true, 60 | "deletable": true, 61 | "editable": true 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "import csv\n", 66 | "\n", 67 | "def find_airports(airport1, airport2, in_file_path):\n", 68 | " f = open(in_file_path)\n", 69 | " reader = csv.reader(f, delimiter=',') \n", 70 | " \n", 71 | " for row in reader:\n", 72 | " airport = row[3] \n", 73 | " if airport == airport1 or airport == airport2: \n", 74 | " print('Row #' + str(reader.line_num) + ' ' + str(row))\n", 75 | " " 76 | ] 77 | }, 78 | { 79 | "cell_type": "raw", 80 | "metadata": { 81 | "deletable": true, 82 | "editable": true 83 | }, 84 | "source": [ 85 | "find_airports(\"Russia\", \"Australia\", \"./airports.dat\")" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": { 91 | "deletable": true, 92 | "editable": true 93 | }, 94 | "source": [ 95 | "## Count How Many Airports are in the file" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 25, 101 | "metadata": { 102 | "collapsed": false, 103 | "deletable": true, 104 | "editable": true 105 | }, 106 | "outputs": [ 107 | { 108 | "name": "stdout", 109 | "output_type": "stream", 110 | "text": [ 111 | "237\n" 112 | ] 113 | } 114 | ], 115 | "source": [ 116 | "f = open('airports.dat', encoding='utf8') \n", 117 | "reader = csv.reader(f, delimiter=',') \n", 118 | "\n", 119 | "country_list = []\n", 120 | "for line in reader:\n", 121 | " country_name = line[3]\n", 122 | " if country_name not in country_list:\n", 123 | " country_list.append(country_name)\n", 124 | "\n", 125 | "print(len(country_list))\n" 126 | ] 127 | } 128 | ], 129 | "metadata": { 130 | "kernelspec": { 131 | "display_name": "Python 3", 132 | "language": "python", 133 | "name": "python3" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 3 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython3", 145 | "version": "3.5.2" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 2 150 | } 151 | -------------------------------------------------------------------------------- /Module2/module2_lab1_answer.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | #!/usr/bin/env python3 3 | 4 | header = ['FirstName', 'LastName', 'City', 'Zipcode'] 5 | row1 = ['Greg', 'Corradini', 'Minneapolis', '75432'] 6 | row2 = ['Summer', 'Rae', 'Seattle', '98103'] 7 | # this nested list `table` represents 8 | # a table of rows where the first row 9 | # is the column headers 10 | table = [ 11 | header, 12 | row1, 13 | row2, 14 | ] 15 | 16 | # calculate the max width of the table cell 17 | padding = 2 18 | max_width = 0 19 | for row in table: 20 | new_max = max([len(value) for value in row]) + padding 21 | # only set thew new max if it's actually greater 22 | if new_max > max_width: 23 | max_width = new_max 24 | 25 | # # print out each row of the table 26 | # for row in table: 27 | # cell1, cell2, cell3, cell4 = row 28 | # 29 | # # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to 30 | # # 31 | # # |FirstName |LastName |City |Zipcode | 32 | # # |Greg |Corradini |Minneapolis |75432 | 33 | # # |Summer |Rae |Seattle |98103 | 34 | # # 35 | # # WRITE YOUR CODE BELOW: 36 | # print(cell1,cell2,cell3,cell4) 37 | 38 | 39 | print("\nMETHOD 1: using tabs\n") 40 | # print out each row of the table 41 | for row in table: 42 | cell1, cell2, cell3, cell4 = row 43 | 44 | # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to 45 | # 46 | # |FirstName |LastName |City |Zipcode | 47 | # |Greg |Corradini |Minneapolis |75432 | 48 | # |Summer |Rae |Seattle |98103 | 49 | # 50 | # WRITE YOUR CODE BELOW: 51 | print("|{}\t|{}\t|{}\t|{}\t|".format(cell1,cell2,cell3,cell4)) 52 | 53 | 54 | print("\nMETHOD 2: using spaces\n") 55 | # print out each row of the table 56 | for row in table: 57 | cell1, cell2, cell3, cell4 = row 58 | 59 | # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to 60 | # |FirstName |LastName |City |Zipcode | 61 | # |Greg |Corradini |Minneapolis |75432 | 62 | # |Summer |Rae |Seattle |98103 | 63 | # WRITE YOUR CODE BELOW: 64 | print("|{} |{} |{} |{} |".format(cell1,cell2,cell3,cell4)) 65 | 66 | 67 | print("\nMETHOD 3: using string functions you haven't learned about yet\n") 68 | # print out each row of the table 69 | for row in table: 70 | cell1, cell2, cell3, cell4 = row 71 | 72 | # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to 73 | # 74 | # |FirstName |LastName |City |Zipcode | 75 | # |Greg |Corradini |Minneapolis |75432 | 76 | # |Summer |Rae |Seattle |98103 | 77 | # 78 | # WRITE YOUR CODE BELOW: 79 | print("|{}|{}|{}|{}|".format(cell1.ljust(max_width),cell2.ljust(max_width),cell3.ljust(max_width),cell4.ljust(max_width))) 80 | 81 | print("\nMETHOD 4: advanced shennanigans you might be interested in learning more about\n") 82 | # print out each row of the table 83 | header = table[0] 84 | for row in table: 85 | # zip takes two lists and interleaves them. Example: 86 | # list1 = ['a','b','c'] 87 | # list2 = [1,2,3] 88 | # zipped = zip(list1,list2) 89 | # print( zipped ) 90 | # [('a',1),('b',2),('c',3)] 91 | record = dict(zip(header,row)) 92 | record.update({'width': max_width}) 93 | 94 | # TODO: use the print() function and string formatting to create output that looks sorta/kinda/similar ( but not identical ) to 95 | # 96 | # |FirstName |LastName |City |Zipcode | 97 | # |Greg |Corradini |Minneapolis |75432 | 98 | # |Summer |Rae |Seattle |98103 | 99 | # WRITE YOUR CODE BELOW: 100 | print("|{FirstName:<{width}}|{LastName:<{width}}|{City:<{width}}|{Zipcode:<{width}}|".format( **record )) -------------------------------------------------------------------------------- /Module1/1_course_overview.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Course Overview" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Instructors \n", 15 | "\n", 16 | "Instructor: Summer Rae summe@uw.edu \n", 17 | "Teaching Assistant: Greg Corradini ( Email via Canvas )" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "## Office Hours\n", 25 | "- Sundays, 1pm\n", 26 | "- Starbucks across the street from campus" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## What is this class about\n", 34 | "- Beginning level intro to programming, with python\n", 35 | "- Good for: \n", 36 | " - Beginners\n", 37 | " - Coming from other languages\n", 38 | " - Refesher course\n", 39 | " - Preparation for certificate programs" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## What we'll be learning\n", 47 | "- Basics operations in a Unix environment\n", 48 | "- Fundamentals of programming using Python" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "## Class Format\n", 56 | "\n", 57 | "- Meet weekly from: 1/12/17 to 3/16/17 \n", 58 | "- Online in Zoom https://uwtest.zoom.us/j/830963209 \n", 59 | "- 3 hour lectures, recorded\n", 60 | "- Intro to material\n", 61 | "- Hands on lab with time for questions\n", 62 | "- Repeat\n", 63 | "- Introduce homework\n", 64 | "- Time permitting, begin homework answer/questions" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "## Expectations/Grading\n", 72 | "- Pass/Fail\n", 73 | "- 80% required to pass\n", 74 | "- 80% attendance either online or in class\n", 75 | "- Homework due before the following class" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "## Canvas\n", 83 | "- Assignments and supplemental material in canvas\n", 84 | " - Course videos and programming hints available from previous professor\n", 85 | "- Homwork turned into Canvas\n", 86 | "- Grading in Canvas\n", 87 | "- Discussion/help in Canvas\n", 88 | "- Get an easy 50 points by logging in and [completing an introduction in Canvas](https://canvas.uw.edu/courses/1105303/discussion_topics/3521544)\n", 89 | "\n", 90 | "https://canvas.uw.edu/courses/1105303" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "## Github Repo\n", 98 | "Lecture notes will be posted on Github at the following URL: \n", 99 | "\n", 100 | "https://github.com/summerela/intro_programming_python" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "## Textbook\n", 108 | "\n", 109 | "Required Textbook: Python Programming for the Absolute Beginner, Third Edition, By Michael Dawson ISBN-10: 1435455002 " 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "## Access and accomodations\n", 117 | "\n", 118 | "Disability Resources for Students (DRS) offers resources and coordinates reasonable accommodations for students with disabilities.\n", 119 | "\n", 120 | "Contact DRS at 206-543-8924 or uwdrs@uw.edu or disability.uw.edu" 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "Python 3", 127 | "language": "python", 128 | "name": "python3" 129 | }, 130 | "language_info": { 131 | "codemirror_mode": { 132 | "name": "ipython", 133 | "version": 3 134 | }, 135 | "file_extension": ".py", 136 | "mimetype": "text/x-python", 137 | "name": "python", 138 | "nbconvert_exporter": "python", 139 | "pygments_lexer": "ipython3", 140 | "version": "3.5.2" 141 | } 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 2 145 | } 146 | -------------------------------------------------------------------------------- /Module1/.ipynb_checkpoints/1_course_overview-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Course Overview" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Instructors \n", 15 | "\n", 16 | "Instructor: Summer Rae summe@uw.edu \n", 17 | "Teaching Assistant: Greg Corradini ( Email via Canvas )" 18 | ] 19 | }, 20 | { 21 | "cell_type": "markdown", 22 | "metadata": {}, 23 | "source": [ 24 | "## Office Hours\n", 25 | "- Sundays, 1pm\n", 26 | "- Starbucks across the street from campus" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "## What is this class about\n", 34 | "- Beginning level intro to programming, with python\n", 35 | "- Good for: \n", 36 | " - Beginners\n", 37 | " - Coming from other languages\n", 38 | " - Refesher course\n", 39 | " - Preparation for certificate programs" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "## What we'll be learning\n", 47 | "- Basics operations in a Unix environment\n", 48 | "- Fundamentals of programming using Python" 49 | ] 50 | }, 51 | { 52 | "cell_type": "markdown", 53 | "metadata": {}, 54 | "source": [ 55 | "## Class Format\n", 56 | "\n", 57 | "- Meet weekly from: 1/12/17 to 3/16/17 \n", 58 | "- Online in Zoom https://uwtest.zoom.us/j/830963209 \n", 59 | "- 3 hour lectures, recorded\n", 60 | "- Intro to material\n", 61 | "- Hands on lab with time for questions\n", 62 | "- Repeat\n", 63 | "- Introduce homework\n", 64 | "- Time permitting, begin homework answer/questions" 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "## Expectations/Grading\n", 72 | "- Pass/Fail\n", 73 | "- 80% required to pass\n", 74 | "- 80% attendance either online or in class\n", 75 | "- Homework due before the following class" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "## Canvas\n", 83 | "- Assignments and supplemental material in canvas\n", 84 | " - Course videos and programming hints available from previous professor\n", 85 | "- Homwork turned into Canvas\n", 86 | "- Grading in Canvas\n", 87 | "- Discussion/help in Canvas\n", 88 | "- Get an easy 50 points by logging in and [completing an introduction in Canvas](https://canvas.uw.edu/courses/1105303/discussion_topics/3521544)\n", 89 | "\n", 90 | "https://canvas.uw.edu/courses/1105303" 91 | ] 92 | }, 93 | { 94 | "cell_type": "markdown", 95 | "metadata": {}, 96 | "source": [ 97 | "## Github Repo\n", 98 | "Lecture notes will be posted on Github at the following URL: \n", 99 | "\n", 100 | "https://github.com/summerela/intro_programming_python" 101 | ] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "## Textbook\n", 108 | "\n", 109 | "Required Textbook: Python Programming for the Absolute Beginner, Third Edition, By Michael Dawson ISBN-10: 1435455002 " 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "## Access and accomodations\n", 117 | "\n", 118 | "Disability Resources for Students (DRS) offers resources and coordinates reasonable accommodations for students with disabilities.\n", 119 | "\n", 120 | "Contact DRS at 206-543-8924 or uwdrs@uw.edu or disability.uw.edu" 121 | ] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "Python 3", 127 | "language": "python", 128 | "name": "python3" 129 | }, 130 | "language_info": { 131 | "codemirror_mode": { 132 | "name": "ipython", 133 | "version": 3 134 | }, 135 | "file_extension": ".py", 136 | "mimetype": "text/x-python", 137 | "name": "python", 138 | "nbconvert_exporter": "python", 139 | "pygments_lexer": "ipython3", 140 | "version": "3.5.2" 141 | } 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 2 145 | } 146 | -------------------------------------------------------------------------------- /Module7/lab2/Lab2.md: -------------------------------------------------------------------------------- 1 | # Module 7 Lab 2 2 | 3 | Life is about the `push` and the `pull` 4 | 5 | ## Instructions: 6 | 7 | ### The *Push* 8 | 9 | 0. We just created a file called `hw7.py` with Summer. If we list out the contents of our `Module7` directory that contains our git local repository we should see something like this: 10 | ``` 11 | $ ls -lah 12 | drwxr-xr-x 14 whizmob staff 476B Feb 19 18:55 .git/ 13 | -rw-r--r-- 1 whizmob staff 52B Feb 19 18:24 README.md 14 | -rw-r--r-- 1 whizmob staff 0B Feb 19 19:06 hw7.py 15 | ``` 16 | 17 | 0. Now think about this. What if we wanted to check the "status" of our local repository? Meaning, what if we wanted to list which files have been changed recently or are new? We can use `git` to tell us about this repository by checking the "status" of it. Let's talk about what this means: 18 | ``` 19 | $ git status 20 | # On branch master 21 | # Untracked files: 22 | # (use "git add ..." to include in what will be committed) 23 | # 24 | # hw7.py 25 | nothing added to commit but untracked files present (use "git add" to track) 26 | ``` 27 | 28 | 0. Now we're gonna add `hw7.py` to "staging". Say What? Let's talk about what "staging" means in this context: 29 | ``` 30 | $ git add hw7.py 31 | ``` 32 | 33 | 0. Let's see what the "status" of our local repository is after "staging" something: 34 | ``` 35 | $ git status 36 | # On branch master 37 | # Changes to be committed: 38 | # (use "git reset HEAD ..." to unstage) 39 | # 40 | # new file: hw7.py 41 | # 42 | ``` 43 | 44 | 0. Let's "commit" our changes in staging so they are ready to "push". What does `-m` option do? What's the point of this statement?: 45 | ``` 46 | $ git commit -m "adding homework 7" 47 | [master 098ec88] adding homework 7 48 | 0 files changed 49 | create mode 100644 homework7.py 50 | ``` 51 | 0. Our status has probably changed. Let's talk about it: 52 | ``` 53 | $ git status 54 | # On branch master 55 | # Your branch is ahead of 'origin/master' by 1 commit. 56 | # 57 | nothing to commit (working directory clean) 58 | ``` 59 | 60 | 0. Finally, we are ready to push our changes to the remote respository. You will be prompted for your `username` and `password`: 61 | ``` 62 | $ git push 63 | Username for 'https://github.com': whizmob 64 | Password for 'https://whizmob@github.com': 65 | Counting objects: 4, done. 66 | Delta compression using up to 4 threads. 67 | Compressing objects: 100% (2/2), done. 68 | Writing objects: 100% (3/3), 286 bytes, done. 69 | Total 3 (delta 0), reused 0 (delta 0) 70 | To https://github.com/whizmob/Module7.git 71 | f95e320..098ec88 master -> master 72 | ``` 73 | 74 | ### The *Pull* 75 | 76 | 0. Now let's go see this file on Github! Go to you repository dashboard and look for `hw7.py` and click on it. Mine is located here `https://github.com/whizmob/Module7/blob/master/hw7.py` 77 | ![1_file](1_file.png) 78 | 79 | 0. Notice that we can edit this file in the browser. Click the edit pencil 80 | ![2_file](2_edit.png) 81 | 82 | 0. Let's make a simple change such as adding a comment above `def print_menu` function 83 | ![3_comment](3_comment.png) 84 | 85 | 0. Scroll to the bottom. Add a commit message about this file edit and click "Commit changes" button 86 | ![4_commit](4_commit.png) 87 | 88 | 0. Assuming that went well, then let's go back to our terminal window. It's always a good idea to recheck your 89 | git status to make sure everything is still gravy: 90 | ``` 91 | $ git status 92 | # On branch master 93 | nothing to commit (working directory clean) 94 | ``` 95 | 96 | 0. Finally, let's "pull" our changes from the remote repo down to our local repo. 97 | ``` 98 | $ git pull 99 | remote: Counting objects: 3, done. 100 | remote: Compressing objects: 100% (3/3), done. 101 | remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 102 | Unpacking objects: 100% (3/3), done. 103 | From https://github.com/whizmob/Module7 104 | 6d999f1..f84d8d4 master -> origin/master 105 | Updating 6d999f1..f84d8d4 106 | Fast-forward 107 | hw7.py | 3 +++ 108 | 1 file changed, 3 insertions(+) 109 | ``` 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /Module8/1_install_jupyter.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Jupyter Notebook Installation" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": { 16 | "deletable": true, 17 | "editable": true 18 | }, 19 | "source": [ 20 | "## Install iPython\n", 21 | "Before class, please try to work through the following installation tutorial. \n", 22 | "\n", 23 | "If the following steps prove to be too troublesome for your computer, you can try using [this chrome extension](https://chrome.google.com/webstore/detail/colaboratory-notebook/pianggobfjcgeihlmfhfgkfalopndooo) instead. \n", 24 | "\n", 25 | "#### Mac\n", 26 | "From your terminal: " 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": { 33 | "collapsed": true, 34 | "deletable": true, 35 | "editable": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "pip3 install ipython # this should already be installed, but just in case" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "deletable": true, 46 | "editable": true 47 | }, 48 | "source": [ 49 | "#### Windows\n", 50 | "\n", 51 | "1. Install [setuptools](https://pypi.python.org/pypi/setuptools)\n", 52 | "2. Install [pyreadline](http://pypi.python.org/pypi/pyreadline)\n", 53 | "3. Install [ipython](http://ipython.org/download.html)" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": { 59 | "deletable": true, 60 | "editable": true 61 | }, 62 | "source": [ 63 | "** If there are any missing dependencies, such as shown in the error below, install those, too. **" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": { 70 | "collapsed": true, 71 | "deletable": true, 72 | "editable": true 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "ImportError: No module named 'nose'" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": { 82 | "deletable": true, 83 | "editable": true 84 | }, 85 | "source": [ 86 | "When you see errors such as the one above, you should try to pip install the missing module:" 87 | ] 88 | }, 89 | { 90 | "cell_type": "code", 91 | "execution_count": null, 92 | "metadata": { 93 | "collapsed": true, 94 | "deletable": true, 95 | "editable": true 96 | }, 97 | "outputs": [], 98 | "source": [ 99 | "pip3 install nose" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": { 105 | "deletable": true, 106 | "editable": true 107 | }, 108 | "source": [ 109 | "## Install Pandoc (for saving to PDF)\n", 110 | "Follow the instructions [here](http://pandoc.org/installing.html) to install PanDoc for your OS." 111 | ] 112 | }, 113 | { 114 | "cell_type": "markdown", 115 | "metadata": { 116 | "deletable": true, 117 | "editable": true 118 | }, 119 | "source": [ 120 | "## Install Graphics Modules" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": null, 126 | "metadata": { 127 | "collapsed": true, 128 | "deletable": true, 129 | "editable": true 130 | }, 131 | "outputs": [], 132 | "source": [ 133 | "pip3 install matplotlib" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": { 140 | "collapsed": true, 141 | "deletable": true, 142 | "editable": true 143 | }, 144 | "outputs": [], 145 | "source": [ 146 | "pip3 install plotly" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": {}, 152 | "source": [ 153 | "## Install Computational Modules" 154 | ] 155 | }, 156 | { 157 | "cell_type": "code", 158 | "execution_count": null, 159 | "metadata": { 160 | "collapsed": true 161 | }, 162 | "outputs": [], 163 | "source": [ 164 | "pip3 install scipy" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "metadata": { 171 | "collapsed": true 172 | }, 173 | "outputs": [], 174 | "source": [ 175 | "pip3 install numpy" 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": null, 181 | "metadata": { 182 | "collapsed": true 183 | }, 184 | "outputs": [], 185 | "source": [ 186 | "pip3 install pandas" 187 | ] 188 | } 189 | ], 190 | "metadata": { 191 | "kernelspec": { 192 | "display_name": "Python 3", 193 | "language": "python", 194 | "name": "python3" 195 | }, 196 | "language_info": { 197 | "codemirror_mode": { 198 | "name": "ipython", 199 | "version": 3 200 | }, 201 | "file_extension": ".py", 202 | "mimetype": "text/x-python", 203 | "name": "python", 204 | "nbconvert_exporter": "python", 205 | "pygments_lexer": "ipython3", 206 | "version": "3.5.2" 207 | } 208 | }, 209 | "nbformat": 4, 210 | "nbformat_minor": 2 211 | } 212 | -------------------------------------------------------------------------------- /Module6/iris.csv: -------------------------------------------------------------------------------- 1 | 5.1,3.5,1.4,0.2,Iris-setosa 2 | 4.9,3.0,1.4,0.2,Iris-setosa 3 | 4.7,3.2,1.3,0.2,Iris-setosa 4 | 4.6,3.1,1.5,0.2,Iris-setosa 5 | 5.0,3.6,1.4,0.2,Iris-setosa 6 | 5.4,3.9,1.7,0.4,Iris-setosa 7 | 4.6,3.4,1.4,0.3,Iris-setosa 8 | 5.0,3.4,1.5,0.2,Iris-setosa 9 | 4.4,2.9,1.4,0.2,Iris-setosa 10 | 4.9,3.1,1.5,0.1,Iris-setosa 11 | 5.4,3.7,1.5,0.2,Iris-setosa 12 | 4.8,3.4,1.6,0.2,Iris-setosa 13 | 4.8,3.0,1.4,0.1,Iris-setosa 14 | 4.3,3.0,1.1,0.1,Iris-setosa 15 | 5.8,4.0,1.2,0.2,Iris-setosa 16 | 5.7,4.4,1.5,0.4,Iris-setosa 17 | 5.4,3.9,1.3,0.4,Iris-setosa 18 | 5.1,3.5,1.4,0.3,Iris-setosa 19 | 5.7,3.8,1.7,0.3,Iris-setosa 20 | 5.1,3.8,1.5,0.3,Iris-setosa 21 | 5.4,3.4,1.7,0.2,Iris-setosa 22 | 5.1,3.7,1.5,0.4,Iris-setosa 23 | 4.6,3.6,1.0,0.2,Iris-setosa 24 | 5.1,3.3,1.7,0.5,Iris-setosa 25 | 4.8,3.4,1.9,0.2,Iris-setosa 26 | 5.0,3.0,1.6,0.2,Iris-setosa 27 | 5.0,3.4,1.6,0.4,Iris-setosa 28 | 5.2,3.5,1.5,0.2,Iris-setosa 29 | 5.2,3.4,1.4,0.2,Iris-setosa 30 | 4.7,3.2,1.6,0.2,Iris-setosa 31 | 4.8,3.1,1.6,0.2,Iris-setosa 32 | 5.4,3.4,1.5,0.4,Iris-setosa 33 | 5.2,4.1,1.5,0.1,Iris-setosa 34 | 5.5,4.2,1.4,0.2,Iris-setosa 35 | 4.9,3.1,1.5,0.1,Iris-setosa 36 | 5.0,3.2,1.2,0.2,Iris-setosa 37 | 5.5,3.5,1.3,0.2,Iris-setosa 38 | 4.9,3.1,1.5,0.1,Iris-setosa 39 | 4.4,3.0,1.3,0.2,Iris-setosa 40 | 5.1,3.4,1.5,0.2,Iris-setosa 41 | 5.0,3.5,1.3,0.3,Iris-setosa 42 | 4.5,2.3,1.3,0.3,Iris-setosa 43 | 4.4,3.2,1.3,0.2,Iris-setosa 44 | 5.0,3.5,1.6,0.6,Iris-setosa 45 | 5.1,3.8,1.9,0.4,Iris-setosa 46 | 4.8,3.0,1.4,0.3,Iris-setosa 47 | 5.1,3.8,1.6,0.2,Iris-setosa 48 | 4.6,3.2,1.4,0.2,Iris-setosa 49 | 5.3,3.7,1.5,0.2,Iris-setosa 50 | 5.0,3.3,1.4,0.2,Iris-setosa 51 | 7.0,3.2,4.7,1.4,Iris-versicolor 52 | 6.4,3.2,4.5,1.5,Iris-versicolor 53 | 6.9,3.1,4.9,1.5,Iris-versicolor 54 | 5.5,2.3,4.0,1.3,Iris-versicolor 55 | 6.5,2.8,4.6,1.5,Iris-versicolor 56 | 5.7,2.8,4.5,1.3,Iris-versicolor 57 | 6.3,3.3,4.7,1.6,Iris-versicolor 58 | 4.9,2.4,3.3,1.0,Iris-versicolor 59 | 6.6,2.9,4.6,1.3,Iris-versicolor 60 | 5.2,2.7,3.9,1.4,Iris-versicolor 61 | 5.0,2.0,3.5,1.0,Iris-versicolor 62 | 5.9,3.0,4.2,1.5,Iris-versicolor 63 | 6.0,2.2,4.0,1.0,Iris-versicolor 64 | 6.1,2.9,4.7,1.4,Iris-versicolor 65 | 5.6,2.9,3.6,1.3,Iris-versicolor 66 | 6.7,3.1,4.4,1.4,Iris-versicolor 67 | 5.6,3.0,4.5,1.5,Iris-versicolor 68 | 5.8,2.7,4.1,1.0,Iris-versicolor 69 | 6.2,2.2,4.5,1.5,Iris-versicolor 70 | 5.6,2.5,3.9,1.1,Iris-versicolor 71 | 5.9,3.2,4.8,1.8,Iris-versicolor 72 | 6.1,2.8,4.0,1.3,Iris-versicolor 73 | 6.3,2.5,4.9,1.5,Iris-versicolor 74 | 6.1,2.8,4.7,1.2,Iris-versicolor 75 | 6.4,2.9,4.3,1.3,Iris-versicolor 76 | 6.6,3.0,4.4,1.4,Iris-versicolor 77 | 6.8,2.8,4.8,1.4,Iris-versicolor 78 | 6.7,3.0,5.0,1.7,Iris-versicolor 79 | 6.0,2.9,4.5,1.5,Iris-versicolor 80 | 5.7,2.6,3.5,1.0,Iris-versicolor 81 | 5.5,2.4,3.8,1.1,Iris-versicolor 82 | 5.5,2.4,3.7,1.0,Iris-versicolor 83 | 5.8,2.7,3.9,1.2,Iris-versicolor 84 | 6.0,2.7,5.1,1.6,Iris-versicolor 85 | 5.4,3.0,4.5,1.5,Iris-versicolor 86 | 6.0,3.4,4.5,1.6,Iris-versicolor 87 | 6.7,3.1,4.7,1.5,Iris-versicolor 88 | 6.3,2.3,4.4,1.3,Iris-versicolor 89 | 5.6,3.0,4.1,1.3,Iris-versicolor 90 | 5.5,2.5,4.0,1.3,Iris-versicolor 91 | 5.5,2.6,4.4,1.2,Iris-versicolor 92 | 6.1,3.0,4.6,1.4,Iris-versicolor 93 | 5.8,2.6,4.0,1.2,Iris-versicolor 94 | 5.0,2.3,3.3,1.0,Iris-versicolor 95 | 5.6,2.7,4.2,1.3,Iris-versicolor 96 | 5.7,3.0,4.2,1.2,Iris-versicolor 97 | 5.7,2.9,4.2,1.3,Iris-versicolor 98 | 6.2,2.9,4.3,1.3,Iris-versicolor 99 | 5.1,2.5,3.0,1.1,Iris-versicolor 100 | 5.7,2.8,4.1,1.3,Iris-versicolor 101 | 6.3,3.3,6.0,2.5,Iris-virginica 102 | 5.8,2.7,5.1,1.9,Iris-virginica 103 | 7.1,3.0,5.9,2.1,Iris-virginica 104 | 6.3,2.9,5.6,1.8,Iris-virginica 105 | 6.5,3.0,5.8,2.2,Iris-virginica 106 | 7.6,3.0,6.6,2.1,Iris-virginica 107 | 4.9,2.5,4.5,1.7,Iris-virginica 108 | 7.3,2.9,6.3,1.8,Iris-virginica 109 | 6.7,2.5,5.8,1.8,Iris-virginica 110 | 7.2,3.6,6.1,2.5,Iris-virginica 111 | 6.5,3.2,5.1,2.0,Iris-virginica 112 | 6.4,2.7,5.3,1.9,Iris-virginica 113 | 6.8,3.0,5.5,2.1,Iris-virginica 114 | 5.7,2.5,5.0,2.0,Iris-virginica 115 | 5.8,2.8,5.1,2.4,Iris-virginica 116 | 6.4,3.2,5.3,2.3,Iris-virginica 117 | 6.5,3.0,5.5,1.8,Iris-virginica 118 | 7.7,3.8,6.7,2.2,Iris-virginica 119 | 7.7,2.6,6.9,2.3,Iris-virginica 120 | 6.0,2.2,5.0,1.5,Iris-virginica 121 | 6.9,3.2,5.7,2.3,Iris-virginica 122 | 5.6,2.8,4.9,2.0,Iris-virginica 123 | 7.7,2.8,6.7,2.0,Iris-virginica 124 | 6.3,2.7,4.9,1.8,Iris-virginica 125 | 6.7,3.3,5.7,2.1,Iris-virginica 126 | 7.2,3.2,6.0,1.8,Iris-virginica 127 | 6.2,2.8,4.8,1.8,Iris-virginica 128 | 6.1,3.0,4.9,1.8,Iris-virginica 129 | 6.4,2.8,5.6,2.1,Iris-virginica 130 | 7.2,3.0,5.8,1.6,Iris-virginica 131 | 7.4,2.8,6.1,1.9,Iris-virginica 132 | 7.9,3.8,6.4,2.0,Iris-virginica 133 | 6.4,2.8,5.6,2.2,Iris-virginica 134 | 6.3,2.8,5.1,1.5,Iris-virginica 135 | 6.1,2.6,5.6,1.4,Iris-virginica 136 | 7.7,3.0,6.1,2.3,Iris-virginica 137 | 6.3,3.4,5.6,2.4,Iris-virginica 138 | 6.4,3.1,5.5,1.8,Iris-virginica 139 | 6.0,3.0,4.8,1.8,Iris-virginica 140 | 6.9,3.1,5.4,2.1,Iris-virginica 141 | 6.7,3.1,5.6,2.4,Iris-virginica 142 | 6.9,3.1,5.1,2.3,Iris-virginica 143 | 5.8,2.7,5.1,1.9,Iris-virginica 144 | 6.8,3.2,5.9,2.3,Iris-virginica 145 | 6.7,3.3,5.7,2.5,Iris-virginica 146 | 6.7,3.0,5.2,2.3,Iris-virginica 147 | 6.3,2.5,5.0,1.9,Iris-virginica 148 | 6.5,3.0,5.2,2.0,Iris-virginica 149 | 6.2,3.4,5.4,2.3,Iris-virginica 150 | 5.9,3.0,5.1,1.8,Iris-virginica -------------------------------------------------------------------------------- /Module7/3_virtualenv.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "deletable": true, 8 | "editable": true 9 | }, 10 | "source": [ 11 | "# Virtual Environments\n", 12 | "Use different versions of python and python packages for a different project without completely destroying everything ever. \n", 13 | "- container for each python project\n", 14 | "- use different versions of python\n", 15 | "- use different packages and package versions" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "## Install" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "metadata": { 29 | "collapsed": false 30 | }, 31 | "outputs": [], 32 | "source": [ 33 | "pip3 install virtualenv" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "metadata": {}, 39 | "source": [ 40 | "## Create a new virtual environment" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 2, 46 | "metadata": { 47 | "collapsed": true 48 | }, 49 | "outputs": [], 50 | "source": [ 51 | "# at your command prompt, create a folder\n", 52 | "%mkdir test_folder" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": { 59 | "collapsed": false 60 | }, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "/Users/selasady/intro_programming_python/Module7/test_folder\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "# change directory into your new folder\n", 72 | "%cd test_folder/" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "### Environment that includes your globally installed python packages\n", 80 | "- use when your currently installed packages are ok, but you need to install specific new versions" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": { 87 | "collapsed": false 88 | }, 89 | "outputs": [], 90 | "source": [ 91 | "# create a virtualenv\n", 92 | "virtualenv venv " 93 | ] 94 | }, 95 | { 96 | "cell_type": "markdown", 97 | "metadata": {}, 98 | "source": [ 99 | "This will create a folder called test_folder/venv that contains all the files needed to activate your virtual enviornment" 100 | ] 101 | }, 102 | { 103 | "cell_type": "code", 104 | "execution_count": 8, 105 | "metadata": { 106 | "collapsed": false 107 | }, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "\u001b[34mvenv\u001b[m\u001b[m/\r\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "% ls" 119 | ] 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "metadata": {}, 124 | "source": [ 125 | "### Environment with no globally installed packages\n", 126 | "- use when you need to setup a project using different versions than the ones currently installed" 127 | ] 128 | }, 129 | { 130 | "cell_type": "code", 131 | "execution_count": null, 132 | "metadata": { 133 | "collapsed": true 134 | }, 135 | "outputs": [], 136 | "source": [ 137 | "# create a virtualenv with no installed packages\n", 138 | "virtualenv venv --no-site-packages" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "## Create a virtual environment with a specific version of python" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": { 152 | "collapsed": true 153 | }, 154 | "outputs": [], 155 | "source": [ 156 | "# py3env is the name we're giving to this virtual environment\n", 157 | "virtualenv py3env -p python3 --no-site-packages" 158 | ] 159 | }, 160 | { 161 | "cell_type": "markdown", 162 | "metadata": {}, 163 | "source": [ 164 | "## Activate your virtual environment" 165 | ] 166 | }, 167 | { 168 | "cell_type": "code", 169 | "execution_count": null, 170 | "metadata": { 171 | "collapsed": false 172 | }, 173 | "outputs": [], 174 | "source": [ 175 | "source ./venv/bin/activate" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "The name of your virtual environment will now appear before your command line to let you know it's activated." 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": null, 188 | "metadata": { 189 | "collapsed": true 190 | }, 191 | "outputs": [], 192 | "source": [ 193 | "(venv) selasady-macbook:test_folder selasady$ " 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": {}, 199 | "source": [ 200 | "## Deactivate your virtual environment" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": null, 206 | "metadata": { 207 | "collapsed": true 208 | }, 209 | "outputs": [], 210 | "source": [ 211 | "deactivate" 212 | ] 213 | } 214 | ], 215 | "metadata": { 216 | "kernelspec": { 217 | "display_name": "Python 3", 218 | "language": "python", 219 | "name": "python3" 220 | }, 221 | "language_info": { 222 | "codemirror_mode": { 223 | "name": "ipython", 224 | "version": 3 225 | }, 226 | "file_extension": ".py", 227 | "mimetype": "text/x-python", 228 | "name": "python", 229 | "nbconvert_exporter": "python", 230 | "pygments_lexer": "ipython3", 231 | "version": "3.5.2" 232 | } 233 | }, 234 | "nbformat": 4, 235 | "nbformat_minor": 2 236 | } 237 | -------------------------------------------------------------------------------- /Module2/2_python_data_contsructs.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Python Data Contsructs" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Variables\n", 15 | "Think of variables as containers. You create them, you name them, and you determine what value they will store. \n", 16 | "\n", 17 | "#### Naming variables\n", 18 | "my_var = 5\n", 19 | "\n", 20 | "my_var is a made up name for your variable. You can call it whatever you want. " 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "metadata": { 27 | "collapsed": false 28 | }, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "5\n", 35 | "5\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "rando_var = 5 \n", 41 | "steve = 5 \n", 42 | "\n", 43 | "print(rando_var)\n", 44 | "print(steve)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "#### Reserved Words\n", 52 | "Words used to trigger an action cannot be used as variable names: \n", 53 | " \n", 54 | "- and\n", 55 | "- as\n", 56 | "- break\n", 57 | "- del\n", 58 | "- true\n", 59 | "- false\n", 60 | "- int\n", 61 | "- str" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 3, 67 | "metadata": { 68 | "collapsed": false 69 | }, 70 | "outputs": [ 71 | { 72 | "ename": "SyntaxError", 73 | "evalue": "invalid syntax (, line 1)", 74 | "output_type": "error", 75 | "traceback": [ 76 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m break = 'test'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "break = 'test'" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "### Statements and Commands" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Statement\n", 96 | "A complete instruction, like a sentence in English: \n", 97 | "- ex: print(\"Go fish!\")\n", 98 | "\n", 99 | "#### Command\n", 100 | "Think of a command as a verb; you are telling python to do something. \n", 101 | "\n", 102 | "print() \n", 103 | "round() \n", 104 | "sum()\n", 105 | "\n", 106 | "- Always lowercase!\n", 107 | "\n", 108 | "#### Expressions\n", 109 | "Expressions don't have any action to them, but they contain values. \n", 110 | "\n", 111 | "- \"Go fish!\"\n", 112 | "- 27 + 12\n" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "## Formatting" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "### Line Continuation Characters\n", 127 | "To make things pretty, or to continue a long function on the next line, use \"\\\": " 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 8, 133 | "metadata": { 134 | "collapsed": false 135 | }, 136 | "outputs": [], 137 | "source": [ 138 | "def my_long_function():\n", 139 | " print(\"My string \\\n", 140 | " is really long \\\n", 141 | " and has to be continued \\\n", 142 | " on another line\")" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "### Escape Sequences\n", 150 | "Using escape sequences allows you to put special characters in your strings. \n", 151 | "\n", 152 | "Two parts: \n", 153 | "- backslash tells the computer that what follows is not a regular string\n", 154 | "- followed by a special reserved character\n", 155 | "\n", 156 | "Examples: \n", 157 | "\\a = make a system sound\n", 158 | "\\t = tabs\n", 159 | "\\n = new line\n", 160 | "\n", 161 | "Real life use: \n", 162 | "\\\\ = insert a backslash into a string\n", 163 | "\\' = single quote" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 3, 169 | "metadata": { 170 | "collapsed": false 171 | }, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "'Goonies never say die,' she screamed!\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "print(\"'Goonies never say die,' she screamed!\")" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "### Quotes\n", 190 | "How do we put quotes in a string? " 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 5, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "'What did she say?' he said\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "my_string = \"'What did she say?' he said\"\n", 210 | "print(my_string)" 211 | ] 212 | } 213 | ], 214 | "metadata": { 215 | "kernelspec": { 216 | "display_name": "Python 3", 217 | "language": "python", 218 | "name": "python3" 219 | }, 220 | "language_info": { 221 | "codemirror_mode": { 222 | "name": "ipython", 223 | "version": 3 224 | }, 225 | "file_extension": ".py", 226 | "mimetype": "text/x-python", 227 | "name": "python", 228 | "nbconvert_exporter": "python", 229 | "pygments_lexer": "ipython3", 230 | "version": "3.5.2" 231 | } 232 | }, 233 | "nbformat": 4, 234 | "nbformat_minor": 2 235 | } 236 | -------------------------------------------------------------------------------- /Module2/.ipynb_checkpoints/2_python_data_contsructs-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## Python Data Contsructs" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Variables\n", 15 | "Think of variables as containers. You create them, you name them, and you determine what value they will store. \n", 16 | "\n", 17 | "#### Naming variables\n", 18 | "my_var = 5\n", 19 | "\n", 20 | "my_var is a made up name for your variable. You can call it whatever you want. " 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 1, 26 | "metadata": { 27 | "collapsed": false 28 | }, 29 | "outputs": [ 30 | { 31 | "name": "stdout", 32 | "output_type": "stream", 33 | "text": [ 34 | "5\n", 35 | "5\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "rando_var = 5 \n", 41 | "steve = 5 \n", 42 | "\n", 43 | "print(rando_var)\n", 44 | "print(steve)" 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "#### Reserved Words\n", 52 | "Words used to trigger an action cannot be used as variable names: \n", 53 | " \n", 54 | "- and\n", 55 | "- as\n", 56 | "- break\n", 57 | "- del\n", 58 | "- true\n", 59 | "- false\n", 60 | "- int\n", 61 | "- str" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 3, 67 | "metadata": { 68 | "collapsed": false 69 | }, 70 | "outputs": [ 71 | { 72 | "ename": "SyntaxError", 73 | "evalue": "invalid syntax (, line 1)", 74 | "output_type": "error", 75 | "traceback": [ 76 | "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m break = 'test'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" 77 | ] 78 | } 79 | ], 80 | "source": [ 81 | "break = 'test'" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "### Statements and Commands" 89 | ] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "#### Statement\n", 96 | "A complete instruction, like a sentence in English: \n", 97 | "- ex: print(\"Go fish!\")\n", 98 | "\n", 99 | "#### Command\n", 100 | "Think of a command as a verb; you are telling python to do something. \n", 101 | "\n", 102 | "print() \n", 103 | "round() \n", 104 | "sum()\n", 105 | "\n", 106 | "- Always lowercase!\n", 107 | "\n", 108 | "#### Expressions\n", 109 | "Expressions don't have any action to them, but they contain values. \n", 110 | "\n", 111 | "- \"Go fish!\"\n", 112 | "- 27 + 12\n" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "## Formatting" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "### Line Continuation Characters\n", 127 | "To make things pretty, or to continue a long function on the next line, use \"\\\": " 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 8, 133 | "metadata": { 134 | "collapsed": false 135 | }, 136 | "outputs": [], 137 | "source": [ 138 | "def my_long_function():\n", 139 | " print(\"My string \\\n", 140 | " is really long \\\n", 141 | " and has to be continued \\\n", 142 | " on another line\")" 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "### Escape Sequences\n", 150 | "Using escape sequences allows you to put special characters in your strings. \n", 151 | "\n", 152 | "Two parts: \n", 153 | "- backslash tells the computer that what follows is not a regular string\n", 154 | "- followed by a special reserved character\n", 155 | "\n", 156 | "Examples: \n", 157 | "\\a = make a system sound\n", 158 | "\\t = tabs\n", 159 | "\\n = new line\n", 160 | "\n", 161 | "Real life use: \n", 162 | "\\\\ = insert a backslash into a string\n", 163 | "\\' = single quote" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 3, 169 | "metadata": { 170 | "collapsed": false 171 | }, 172 | "outputs": [ 173 | { 174 | "name": "stdout", 175 | "output_type": "stream", 176 | "text": [ 177 | "'Goonies never say die,' she screamed!\n" 178 | ] 179 | } 180 | ], 181 | "source": [ 182 | "print(\"'Goonies never say die,' she screamed!\")" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "### Quotes\n", 190 | "How do we put quotes in a string? " 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 5, 196 | "metadata": { 197 | "collapsed": false 198 | }, 199 | "outputs": [ 200 | { 201 | "name": "stdout", 202 | "output_type": "stream", 203 | "text": [ 204 | "'What did she say?' he said\n" 205 | ] 206 | } 207 | ], 208 | "source": [ 209 | "my_string = \"'What did she say?' he said\"\n", 210 | "print(my_string)" 211 | ] 212 | } 213 | ], 214 | "metadata": { 215 | "kernelspec": { 216 | "display_name": "Python 3", 217 | "language": "python", 218 | "name": "python3" 219 | }, 220 | "language_info": { 221 | "codemirror_mode": { 222 | "name": "ipython", 223 | "version": 3 224 | }, 225 | "file_extension": ".py", 226 | "mimetype": "text/x-python", 227 | "name": "python", 228 | "nbconvert_exporter": "python", 229 | "pygments_lexer": "ipython3", 230 | "version": "3.5.2" 231 | } 232 | }, 233 | "nbformat": 4, 234 | "nbformat_minor": 2 235 | } 236 | -------------------------------------------------------------------------------- /Module3/2_Functions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "## What is a Function? \n", 10 | "A way to make your code re-usable! \n", 11 | "\n", 12 | "Takes input. \n", 13 | "Returns output." 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 21, 19 | "metadata": { 20 | "collapsed": true 21 | }, 22 | "outputs": [], 23 | "source": [ 24 | "def my_function_name(my_input_var):\n", 25 | " new_var = do_something_to(my_output_var)\n", 26 | " return new_var" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": {}, 32 | "source": [ 33 | "### The clunky way \n", 34 | "You want to perform a series of calculations on several numbers. " 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": { 41 | "collapsed": true 42 | }, 43 | "outputs": [], 44 | "source": [ 45 | "num1 = 1\n", 46 | "num2 = 2\n", 47 | "num3 = 3\n", 48 | "num4 = 4\n", 49 | "num5 = 5" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 10, 55 | "metadata": { 56 | "collapsed": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "# convert each number to a percentage and multiply by 2\n", 61 | "num1_pct = (1/100) * 2\n", 62 | "num2_pct = (2/100) * 2\n", 63 | "num3_pct = (3/100) * 2\n", 64 | "num4_pct = (4/100) * 2\n", 65 | "num5_pct = (5/100) * 2" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 11, 71 | "metadata": { 72 | "collapsed": false 73 | }, 74 | "outputs": [ 75 | { 76 | "data": { 77 | "text/plain": [ 78 | "0.02" 79 | ] 80 | }, 81 | "execution_count": 11, 82 | "metadata": {}, 83 | "output_type": "execute_result" 84 | } 85 | ], 86 | "source": [ 87 | "num1_pct" 88 | ] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "## A better way\n", 95 | "Make a function. \n", 96 | "\n", 97 | "Notice the indentation here. Remind me to talk about this if I forget!" 98 | ] 99 | }, 100 | { 101 | "cell_type": "code", 102 | "execution_count": 30, 103 | "metadata": { 104 | "collapsed": true 105 | }, 106 | "outputs": [], 107 | "source": [ 108 | "def pct_doubled(input_number):\n", 109 | " new_number = (input_number/100) * 2" 110 | ] 111 | }, 112 | { 113 | "cell_type": "markdown", 114 | "metadata": {}, 115 | "source": [ 116 | "### Abstraction\n", 117 | "The person using the function doesn't need to worry about how the function works, they just need to know how to use it. " 118 | ] 119 | }, 120 | { 121 | "cell_type": "code", 122 | "execution_count": 31, 123 | "metadata": { 124 | "collapsed": false 125 | }, 126 | "outputs": [], 127 | "source": [ 128 | "pct_doubled(12)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "#### Wait, that didn't work!? " 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "metadata": {}, 141 | "source": [ 142 | "### Encapsulation\n", 143 | "Everything stays inside the function unless you tell it to return a value. This keeps each function separate from the other functions. " 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 32, 149 | "metadata": { 150 | "collapsed": true 151 | }, 152 | "outputs": [], 153 | "source": [ 154 | "def pct_doubled_and_returned(input_number):\n", 155 | " new_number = (input_number/100) * 2\n", 156 | " return new_number" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 25, 162 | "metadata": { 163 | "collapsed": false 164 | }, 165 | "outputs": [ 166 | { 167 | "data": { 168 | "text/plain": [ 169 | "0.24" 170 | ] 171 | }, 172 | "execution_count": 25, 173 | "metadata": {}, 174 | "output_type": "execute_result" 175 | } 176 | ], 177 | "source": [ 178 | "pct_doubled_and_returned(12)" 179 | ] 180 | }, 181 | { 182 | "cell_type": "code", 183 | "execution_count": 26, 184 | "metadata": { 185 | "collapsed": false 186 | }, 187 | "outputs": [ 188 | { 189 | "data": { 190 | "text/plain": [ 191 | "0.02" 192 | ] 193 | }, 194 | "execution_count": 26, 195 | "metadata": {}, 196 | "output_type": "execute_result" 197 | } 198 | ], 199 | "source": [ 200 | "pct_doubled_and_returned(1)" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 28, 206 | "metadata": { 207 | "collapsed": false 208 | }, 209 | "outputs": [ 210 | { 211 | "data": { 212 | "text/plain": [ 213 | "0.02" 214 | ] 215 | }, 216 | "execution_count": 28, 217 | "metadata": {}, 218 | "output_type": "execute_result" 219 | } 220 | ], 221 | "source": [ 222 | "pct_doubled_and_returned(num1)" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": 23, 228 | "metadata": { 229 | "collapsed": false 230 | }, 231 | "outputs": [ 232 | { 233 | "name": "stdout", 234 | "output_type": "stream", 235 | "text": [ 236 | "0.02\n" 237 | ] 238 | } 239 | ], 240 | "source": [ 241 | "new_num1 = pct_doubled_and_returned(num1)\n", 242 | "print(new_num1)" 243 | ] 244 | } 245 | ], 246 | "metadata": { 247 | "kernelspec": { 248 | "display_name": "Python 3", 249 | "language": "python", 250 | "name": "python3" 251 | }, 252 | "language_info": { 253 | "codemirror_mode": { 254 | "name": "ipython", 255 | "version": 3 256 | }, 257 | "file_extension": ".py", 258 | "mimetype": "text/x-python", 259 | "name": "python", 260 | "nbconvert_exporter": "python", 261 | "pygments_lexer": "ipython3", 262 | "version": "3.5.2" 263 | } 264 | }, 265 | "nbformat": 4, 266 | "nbformat_minor": 2 267 | } 268 | -------------------------------------------------------------------------------- /Module2/1_review_hw1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 1" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Components of a basic script" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": { 21 | "collapsed": false 22 | }, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "Hello there, world!\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "#!/bin/env python3\n", 34 | "\n", 35 | "# import your modules here\n", 36 | "import os\n", 37 | "\n", 38 | "# do things\n", 39 | "print(\"Hello there, world!\")\n", 40 | "\n", 41 | "# quit and close anything you opened\n", 42 | "quit()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Python Shebang" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Unix\n", 57 | "The shebang allows you to run a script without having to type \"python\" first\n", 58 | "\n", 59 | "### Windows\n", 60 | "A shebang isn't necessary for Windows, windows associates a file to a program using the file extension \".py\"" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "#!/usr/bin/env python3\n", 68 | "\n", 69 | "- /usr/bin = standard path to your program files\n", 70 | "- env = if it's not in your standard path, check your system path\n", 71 | "- python3 = language to use for interpreting the rest of your script" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "## Strings\n", 79 | "\n", 80 | "How do you assign a string to a variable? \n", 81 | "Quotes. " 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "metadata": { 88 | "collapsed": true 89 | }, 90 | "outputs": [], 91 | "source": [ 92 | "my_string = \"Hello world!\"" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 2, 98 | "metadata": { 99 | "collapsed": false 100 | }, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "'Hello world!'" 106 | ] 107 | }, 108 | "execution_count": 2, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "my_string" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "## Integers\n", 122 | "How do you assign an integer to a variable? \n", 123 | "Give it a number. " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 3, 129 | "metadata": { 130 | "collapsed": true 131 | }, 132 | "outputs": [], 133 | "source": [ 134 | "my_integer = 27" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 4, 140 | "metadata": { 141 | "collapsed": false 142 | }, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "27" 148 | ] 149 | }, 150 | "execution_count": 4, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "my_integer" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "## Floats\n", 164 | "What the heck is a float? \n", 165 | "A number with decimal precision. " 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 5, 171 | "metadata": { 172 | "collapsed": true 173 | }, 174 | "outputs": [], 175 | "source": [ 176 | "my_float = 2.945453454" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 6, 182 | "metadata": { 183 | "collapsed": false 184 | }, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "2.945453454" 190 | ] 191 | }, 192 | "execution_count": 6, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "my_float" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "#### And what if I want to round it, such as in tracking dollars? " 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 8, 211 | "metadata": { 212 | "collapsed": true 213 | }, 214 | "outputs": [], 215 | "source": [ 216 | "my_money = round(my_float, 2)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 9, 222 | "metadata": { 223 | "collapsed": false 224 | }, 225 | "outputs": [ 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "2.95" 230 | ] 231 | }, 232 | "execution_count": 9, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "my_money" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 10, 244 | "metadata": { 245 | "collapsed": false 246 | }, 247 | "outputs": [ 248 | { 249 | "data": { 250 | "text/plain": [ 251 | "2.945453454" 252 | ] 253 | }, 254 | "execution_count": 10, 255 | "metadata": {}, 256 | "output_type": "execute_result" 257 | } 258 | ], 259 | "source": [ 260 | "my_float" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": { 267 | "collapsed": true 268 | }, 269 | "outputs": [], 270 | "source": [] 271 | } 272 | ], 273 | "metadata": { 274 | "kernelspec": { 275 | "display_name": "Python 3", 276 | "language": "python", 277 | "name": "python3" 278 | }, 279 | "language_info": { 280 | "codemirror_mode": { 281 | "name": "ipython", 282 | "version": 3 283 | }, 284 | "file_extension": ".py", 285 | "mimetype": "text/x-python", 286 | "name": "python", 287 | "nbconvert_exporter": "python", 288 | "pygments_lexer": "ipython3", 289 | "version": "3.5.2" 290 | } 291 | }, 292 | "nbformat": 4, 293 | "nbformat_minor": 2 294 | } 295 | -------------------------------------------------------------------------------- /Module2/.ipynb_checkpoints/1_review_hw1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Homework 1" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Components of a basic script" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": { 21 | "collapsed": false 22 | }, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "Hello there, world!\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "#!/bin/env python3\n", 34 | "\n", 35 | "# import your modules here\n", 36 | "import os\n", 37 | "\n", 38 | "# do things\n", 39 | "print(\"Hello there, world!\")\n", 40 | "\n", 41 | "# quit and close anything you opened\n", 42 | "quit()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "## Python Shebang" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "### Unix\n", 57 | "The shebang allows you to run a script without having to type \"python\" first\n", 58 | "\n", 59 | "### Windows\n", 60 | "A shebang isn't necessary for Windows, windows associates a file to a program using the file extension \".py\"" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "#!/usr/bin/env python3\n", 68 | "\n", 69 | "- /usr/bin = standard path to your program files\n", 70 | "- env = if it's not in your standard path, check your system path\n", 71 | "- python3 = language to use for interpreting the rest of your script" 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "## Strings\n", 79 | "\n", 80 | "How do you assign a string to a variable? \n", 81 | "Quotes. " 82 | ] 83 | }, 84 | { 85 | "cell_type": "code", 86 | "execution_count": 1, 87 | "metadata": { 88 | "collapsed": true 89 | }, 90 | "outputs": [], 91 | "source": [ 92 | "my_string = \"Hello world!\"" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": 2, 98 | "metadata": { 99 | "collapsed": false 100 | }, 101 | "outputs": [ 102 | { 103 | "data": { 104 | "text/plain": [ 105 | "'Hello world!'" 106 | ] 107 | }, 108 | "execution_count": 2, 109 | "metadata": {}, 110 | "output_type": "execute_result" 111 | } 112 | ], 113 | "source": [ 114 | "my_string" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "## Integers\n", 122 | "How do you assign an integer to a variable? \n", 123 | "Give it a number. " 124 | ] 125 | }, 126 | { 127 | "cell_type": "code", 128 | "execution_count": 3, 129 | "metadata": { 130 | "collapsed": true 131 | }, 132 | "outputs": [], 133 | "source": [ 134 | "my_integer = 27" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 4, 140 | "metadata": { 141 | "collapsed": false 142 | }, 143 | "outputs": [ 144 | { 145 | "data": { 146 | "text/plain": [ 147 | "27" 148 | ] 149 | }, 150 | "execution_count": 4, 151 | "metadata": {}, 152 | "output_type": "execute_result" 153 | } 154 | ], 155 | "source": [ 156 | "my_integer" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "## Floats\n", 164 | "What the heck is a float? \n", 165 | "A number with decimal precision. " 166 | ] 167 | }, 168 | { 169 | "cell_type": "code", 170 | "execution_count": 5, 171 | "metadata": { 172 | "collapsed": true 173 | }, 174 | "outputs": [], 175 | "source": [ 176 | "my_float = 2.945453454" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 6, 182 | "metadata": { 183 | "collapsed": false 184 | }, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "2.945453454" 190 | ] 191 | }, 192 | "execution_count": 6, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "my_float" 199 | ] 200 | }, 201 | { 202 | "cell_type": "markdown", 203 | "metadata": {}, 204 | "source": [ 205 | "#### And what if I want to round it, such as in tracking dollars? " 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 8, 211 | "metadata": { 212 | "collapsed": true 213 | }, 214 | "outputs": [], 215 | "source": [ 216 | "my_money = round(my_float, 2)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 9, 222 | "metadata": { 223 | "collapsed": false 224 | }, 225 | "outputs": [ 226 | { 227 | "data": { 228 | "text/plain": [ 229 | "2.95" 230 | ] 231 | }, 232 | "execution_count": 9, 233 | "metadata": {}, 234 | "output_type": "execute_result" 235 | } 236 | ], 237 | "source": [ 238 | "my_money" 239 | ] 240 | }, 241 | { 242 | "cell_type": "code", 243 | "execution_count": 10, 244 | "metadata": { 245 | "collapsed": false 246 | }, 247 | "outputs": [ 248 | { 249 | "data": { 250 | "text/plain": [ 251 | "2.945453454" 252 | ] 253 | }, 254 | "execution_count": 10, 255 | "metadata": {}, 256 | "output_type": "execute_result" 257 | } 258 | ], 259 | "source": [ 260 | "my_float" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": null, 266 | "metadata": { 267 | "collapsed": true 268 | }, 269 | "outputs": [], 270 | "source": [] 271 | } 272 | ], 273 | "metadata": { 274 | "kernelspec": { 275 | "display_name": "Python 3", 276 | "language": "python", 277 | "name": "python3" 278 | }, 279 | "language_info": { 280 | "codemirror_mode": { 281 | "name": "ipython", 282 | "version": 3 283 | }, 284 | "file_extension": ".py", 285 | "mimetype": "text/x-python", 286 | "name": "python", 287 | "nbconvert_exporter": "python", 288 | "pygments_lexer": "ipython3", 289 | "version": "3.5.2" 290 | } 291 | }, 292 | "nbformat": 4, 293 | "nbformat_minor": 2 294 | } 295 | -------------------------------------------------------------------------------- /Module5/1_Sets.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "deletable": true, 7 | "editable": true 8 | }, 9 | "source": [ 10 | "# Sets\n", 11 | "A list that only contains unique elements" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 7, 17 | "metadata": { 18 | "collapsed": true, 19 | "deletable": true, 20 | "editable": true 21 | }, 22 | "outputs": [], 23 | "source": [ 24 | "test_string = \"what the what ?\"" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 8, 30 | "metadata": { 31 | "collapsed": false, 32 | "deletable": true, 33 | "editable": true 34 | }, 35 | "outputs": [ 36 | { 37 | "data": { 38 | "text/plain": [ 39 | "{'?', 'the', 'what'}" 40 | ] 41 | }, 42 | "execution_count": 8, 43 | "metadata": {}, 44 | "output_type": "execute_result" 45 | } 46 | ], 47 | "source": [ 48 | "set(test_string.split(\" \"))" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 9, 54 | "metadata": { 55 | "collapsed": true, 56 | "deletable": true, 57 | "editable": true 58 | }, 59 | "outputs": [], 60 | "source": [ 61 | "test_list = [1,1,1,2]" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 10, 67 | "metadata": { 68 | "collapsed": false, 69 | "deletable": true, 70 | "editable": true 71 | }, 72 | "outputs": [ 73 | { 74 | "data": { 75 | "text/plain": [ 76 | "{1, 2}" 77 | ] 78 | }, 79 | "execution_count": 10, 80 | "metadata": {}, 81 | "output_type": "execute_result" 82 | } 83 | ], 84 | "source": [ 85 | "set(test_list)" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": { 91 | "deletable": true, 92 | "editable": true 93 | }, 94 | "source": [ 95 | "## Intersection\n", 96 | "Which items occur in both sets? " 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": 11, 102 | "metadata": { 103 | "collapsed": true, 104 | "deletable": true, 105 | "editable": true 106 | }, 107 | "outputs": [], 108 | "source": [ 109 | "a = set([\"Jake\", \"John\", \"Eric\"])\n", 110 | "b = set([\"John\", \"Jill\"])" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 12, 116 | "metadata": { 117 | "collapsed": false, 118 | "deletable": true, 119 | "editable": true 120 | }, 121 | "outputs": [ 122 | { 123 | "data": { 124 | "text/plain": [ 125 | "{'John'}" 126 | ] 127 | }, 128 | "execution_count": 12, 129 | "metadata": {}, 130 | "output_type": "execute_result" 131 | } 132 | ], 133 | "source": [ 134 | "a.intersection(b)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "code", 139 | "execution_count": 13, 140 | "metadata": { 141 | "collapsed": false, 142 | "deletable": true, 143 | "editable": true 144 | }, 145 | "outputs": [ 146 | { 147 | "data": { 148 | "text/plain": [ 149 | "{'John'}" 150 | ] 151 | }, 152 | "execution_count": 13, 153 | "metadata": {}, 154 | "output_type": "execute_result" 155 | } 156 | ], 157 | "source": [ 158 | "b.intersection(a)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": { 164 | "deletable": true, 165 | "editable": true 166 | }, 167 | "source": [ 168 | "## Symmetric Difference\n", 169 | "Which items occur in only one set? " 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 14, 175 | "metadata": { 176 | "collapsed": false, 177 | "deletable": true, 178 | "editable": true 179 | }, 180 | "outputs": [ 181 | { 182 | "data": { 183 | "text/plain": [ 184 | "{'Eric', 'Jake', 'Jill'}" 185 | ] 186 | }, 187 | "execution_count": 14, 188 | "metadata": {}, 189 | "output_type": "execute_result" 190 | } 191 | ], 192 | "source": [ 193 | "a.symmetric_difference(b)" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "metadata": { 199 | "deletable": true, 200 | "editable": true 201 | }, 202 | "source": [ 203 | "## Difference\n", 204 | "Which items occur in only one list and not the other? " 205 | ] 206 | }, 207 | { 208 | "cell_type": "code", 209 | "execution_count": 15, 210 | "metadata": { 211 | "collapsed": false, 212 | "deletable": true, 213 | "editable": true 214 | }, 215 | "outputs": [ 216 | { 217 | "data": { 218 | "text/plain": [ 219 | "{'Eric', 'Jake'}" 220 | ] 221 | }, 222 | "execution_count": 15, 223 | "metadata": {}, 224 | "output_type": "execute_result" 225 | } 226 | ], 227 | "source": [ 228 | "a.difference(b)" 229 | ] 230 | }, 231 | { 232 | "cell_type": "code", 233 | "execution_count": 16, 234 | "metadata": { 235 | "collapsed": false, 236 | "deletable": true, 237 | "editable": true 238 | }, 239 | "outputs": [ 240 | { 241 | "data": { 242 | "text/plain": [ 243 | "{'Jill'}" 244 | ] 245 | }, 246 | "execution_count": 16, 247 | "metadata": {}, 248 | "output_type": "execute_result" 249 | } 250 | ], 251 | "source": [ 252 | "b.difference(a)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "metadata": { 258 | "deletable": true, 259 | "editable": true 260 | }, 261 | "source": [ 262 | "## Union\n", 263 | "List all members of both sets" 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 17, 269 | "metadata": { 270 | "collapsed": false, 271 | "deletable": true, 272 | "editable": true 273 | }, 274 | "outputs": [ 275 | { 276 | "data": { 277 | "text/plain": [ 278 | "{'Eric', 'Jake', 'Jill', 'John'}" 279 | ] 280 | }, 281 | "execution_count": 17, 282 | "metadata": {}, 283 | "output_type": "execute_result" 284 | } 285 | ], 286 | "source": [ 287 | "a.union(b)" 288 | ] 289 | }, 290 | { 291 | "cell_type": "markdown", 292 | "metadata": { 293 | "deletable": true, 294 | "editable": true 295 | }, 296 | "source": [ 297 | "## HW 4 Example: \n", 298 | "Write a function that counts the number of airports in each country and prints out the total counts." 299 | ] 300 | }, 301 | { 302 | "cell_type": "code", 303 | "execution_count": 4, 304 | "metadata": { 305 | "collapsed": false, 306 | "deletable": true, 307 | "editable": true 308 | }, 309 | "outputs": [ 310 | { 311 | "name": "stdout", 312 | "output_type": "stream", 313 | "text": [ 314 | "237\n" 315 | ] 316 | } 317 | ], 318 | "source": [ 319 | "import csv\n", 320 | "f = open('airports.dat', encoding='utf8') \n", 321 | "reader = csv.reader(f, delimiter=',') \n", 322 | "\n", 323 | "country_list = []\n", 324 | "for line in reader:\n", 325 | " country_name = line[3]\n", 326 | " country_list.append(country_name)\n", 327 | "\n", 328 | "print(len(set(country_list)))\n", 329 | "\n" 330 | ] 331 | } 332 | ], 333 | "metadata": { 334 | "kernelspec": { 335 | "display_name": "Python 3", 336 | "language": "python", 337 | "name": "python3" 338 | }, 339 | "language_info": { 340 | "codemirror_mode": { 341 | "name": "ipython", 342 | "version": 3 343 | }, 344 | "file_extension": ".py", 345 | "mimetype": "text/x-python", 346 | "name": "python", 347 | "nbconvert_exporter": "python", 348 | "pygments_lexer": "ipython3", 349 | "version": "3.5.2" 350 | } 351 | }, 352 | "nbformat": 4, 353 | "nbformat_minor": 2 354 | } 355 | -------------------------------------------------------------------------------- /Module9/2_more_classes.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "deletable": true, 8 | "editable": true 9 | }, 10 | "source": [ 11 | "# More on classes" 12 | ] 13 | }, 14 | { 15 | "cell_type": "code", 16 | "execution_count": 1, 17 | "metadata": { 18 | "collapsed": true 19 | }, 20 | "outputs": [], 21 | "source": [ 22 | "class Critter():\n", 23 | " \n", 24 | " def __init__(self, name):\n", 25 | " # name is an attribute of the Critter class\n", 26 | " self.name = name\n", 27 | " print(\"A new critter, {}, has been born!\".format(self.name))\n", 28 | " \n", 29 | " # define a method, using the self parameter\n", 30 | " def talk(self):\n", 31 | " print(\"Hi. I'm {}\".format(self.name))\n", 32 | " \n", 33 | " # using python's __str__ method\n", 34 | " def __str__(self):\n", 35 | " rep = \"Critter object\\n \"\n", 36 | " rep += \"name: {} \\n\".format(self.name)\n", 37 | " return rep\n" 38 | ] 39 | }, 40 | { 41 | "cell_type": "markdown", 42 | "metadata": {}, 43 | "source": [ 44 | "## Class attributes \n", 45 | "Attributes that belong to the class itself, and not an instance of the class\n", 46 | "- These attributes are shared by all instances of the class" 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 9, 52 | "metadata": { 53 | "collapsed": true 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "class Critter():\n", 58 | " \n", 59 | " total = 0\n", 60 | " \n", 61 | " def __init__(self, name):\n", 62 | " # name is an attribute of the Critter class\n", 63 | " self.name = name\n", 64 | " print(\"A new critter, {}, has been born!\".format(self.name))\n", 65 | " Critter.total += 1\n", 66 | " \n", 67 | " # define a method, using the self parameter\n", 68 | " def talk(self):\n", 69 | " print(\"Hi. I'm {}\".format(self.name))\n", 70 | " \n", 71 | " # using python's __str__ method\n", 72 | " def __str__(self):\n", 73 | " rep = \"Critter object\\n \"\n", 74 | " rep += \"name: {} \\n\".format(self.name)\n", 75 | " return rep" 76 | ] 77 | }, 78 | { 79 | "cell_type": "code", 80 | "execution_count": 10, 81 | "metadata": { 82 | "collapsed": false 83 | }, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "A new critter, Fred, has been born!\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "crit = Critter(\"Fred\")" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 11, 100 | "metadata": { 101 | "collapsed": false 102 | }, 103 | "outputs": [ 104 | { 105 | "data": { 106 | "text/plain": [ 107 | "1" 108 | ] 109 | }, 110 | "execution_count": 11, 111 | "metadata": {}, 112 | "output_type": "execute_result" 113 | } 114 | ], 115 | "source": [ 116 | "crit.total" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 12, 122 | "metadata": { 123 | "collapsed": false 124 | }, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "A new critter, Sally Lue, has been born!\n" 131 | ] 132 | } 133 | ], 134 | "source": [ 135 | "crit2 = Critter(\"Sally Lue\")" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 13, 141 | "metadata": { 142 | "collapsed": false 143 | }, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "2" 149 | ] 150 | }, 151 | "execution_count": 13, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "crit2.total" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 14, 163 | "metadata": { 164 | "collapsed": false 165 | }, 166 | "outputs": [ 167 | { 168 | "data": { 169 | "text/plain": [ 170 | "2" 171 | ] 172 | }, 173 | "execution_count": 14, 174 | "metadata": {}, 175 | "output_type": "execute_result" 176 | } 177 | ], 178 | "source": [ 179 | "crit.total" 180 | ] 181 | }, 182 | { 183 | "cell_type": "markdown", 184 | "metadata": {}, 185 | "source": [ 186 | "## Static Methods\n", 187 | "Similar to class attributes, these are functions that belong to the class, and not to any particular instance of the class" 188 | ] 189 | }, 190 | { 191 | "cell_type": "code", 192 | "execution_count": 15, 193 | "metadata": { 194 | "collapsed": true 195 | }, 196 | "outputs": [], 197 | "source": [ 198 | "class Critter():\n", 199 | " \n", 200 | " total = 0\n", 201 | " \n", 202 | " def __init__(self, name):\n", 203 | " # name is an attribute of the Critter class\n", 204 | " self.name = name\n", 205 | " print(\"A new critter, {}, has been born!\".format(self.name))\n", 206 | " Critter.total += 1\n", 207 | " \n", 208 | " # define a method, using the self parameter\n", 209 | " def talk(self):\n", 210 | " print(\"Hi. I'm {}\".format(self.name))\n", 211 | " \n", 212 | " # using python's __str__ method\n", 213 | " def __str__(self):\n", 214 | " rep = \"Critter object\\n \"\n", 215 | " rep += \"name: {} \\n\".format(self.name)\n", 216 | " return rep\n", 217 | "\n", 218 | " @staticmethod\n", 219 | " def status():\n", 220 | " print(\"There are {} critters\".format(Critter.total))\n", 221 | " " 222 | ] 223 | }, 224 | { 225 | "cell_type": "code", 226 | "execution_count": 16, 227 | "metadata": { 228 | "collapsed": false 229 | }, 230 | "outputs": [ 231 | { 232 | "name": "stdout", 233 | "output_type": "stream", 234 | "text": [ 235 | "A new critter, Jimbo, has been born!\n" 236 | ] 237 | } 238 | ], 239 | "source": [ 240 | "static_crit = Critter(\"Jimbo\")" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 18, 246 | "metadata": { 247 | "collapsed": false 248 | }, 249 | "outputs": [ 250 | { 251 | "name": "stdout", 252 | "output_type": "stream", 253 | "text": [ 254 | "There are 1 critters\n" 255 | ] 256 | } 257 | ], 258 | "source": [ 259 | "Critter.status()" 260 | ] 261 | }, 262 | { 263 | "cell_type": "code", 264 | "execution_count": 20, 265 | "metadata": { 266 | "collapsed": false 267 | }, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "A new critter, Schubert, has been born!\n" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "static_crit2 = Critter(\"Schubert\")" 279 | ] 280 | }, 281 | { 282 | "cell_type": "code", 283 | "execution_count": 21, 284 | "metadata": { 285 | "collapsed": false 286 | }, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "There are 2 critters\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "Critter.status()" 298 | ] 299 | }, 300 | { 301 | "cell_type": "markdown", 302 | "metadata": {}, 303 | "source": [ 304 | "#### For more info, read your text from pages 226-239" 305 | ] 306 | } 307 | ], 308 | "metadata": { 309 | "kernelspec": { 310 | "display_name": "Python 3", 311 | "language": "python", 312 | "name": "python3" 313 | }, 314 | "language_info": { 315 | "codemirror_mode": { 316 | "name": "ipython", 317 | "version": 3 318 | }, 319 | "file_extension": ".py", 320 | "mimetype": "text/x-python", 321 | "name": "python", 322 | "nbconvert_exporter": "python", 323 | "pygments_lexer": "ipython3", 324 | "version": "3.5.2" 325 | } 326 | }, 327 | "nbformat": 4, 328 | "nbformat_minor": 2 329 | } 330 | -------------------------------------------------------------------------------- /Module5/2_tuples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuples\n", 8 | "- Can store any combination of data types\n", 9 | "- immutable\n", 10 | "- sequence of values, separated by commas" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 11, 16 | "metadata": { 17 | "collapsed": false 18 | }, 19 | "outputs": [], 20 | "source": [ 21 | "my_tuple = (1,\"stuff\", {\"dict_key\": \"dict_val\"}, [1,2,3])" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 12, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "(1, 'stuff', {'dict_key': 'dict_val'}, [1, 2, 3])" 35 | ] 36 | }, 37 | "execution_count": 12, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "my_tuple" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Access tuple items by index" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 13, 56 | "metadata": { 57 | "collapsed": false 58 | }, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "{'dict_key': 'dict_val'}" 64 | ] 65 | }, 66 | "execution_count": 13, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "my_tuple[2]" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 14, 78 | "metadata": { 79 | "collapsed": false 80 | }, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "dict_values(['dict_val'])" 86 | ] 87 | }, 88 | "execution_count": 14, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "my_tuple[2].values()" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "## Iterate through tuple items" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 15, 107 | "metadata": { 108 | "collapsed": false 109 | }, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "1\n", 116 | "stuff\n", 117 | "{'dict_key': 'dict_val'}\n", 118 | "[1, 2, 3]\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "for item in my_tuple:\n", 124 | " print(item)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 16, 130 | "metadata": { 131 | "collapsed": false 132 | }, 133 | "outputs": [ 134 | { 135 | "name": "stdout", 136 | "output_type": "stream", 137 | "text": [ 138 | "0 1\n", 139 | "1 stuff\n", 140 | "2 {'dict_key': 'dict_val'}\n", 141 | "3 [1, 2, 3]\n" 142 | ] 143 | } 144 | ], 145 | "source": [ 146 | "for x,y in enumerate(my_tuple):\n", 147 | " print(x,y)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "## Tuple operations" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 17, 160 | "metadata": { 161 | "collapsed": false 162 | }, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "4" 168 | ] 169 | }, 170 | "execution_count": 17, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "len(my_tuple)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 18, 182 | "metadata": { 183 | "collapsed": false 184 | }, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "True" 190 | ] 191 | }, 192 | "execution_count": 18, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "1 in my_tuple" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 19, 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "outputs": [ 208 | { 209 | "data": { 210 | "text/plain": [ 211 | "False" 212 | ] 213 | }, 214 | "execution_count": 19, 215 | "metadata": {}, 216 | "output_type": "execute_result" 217 | } 218 | ], 219 | "source": [ 220 | "2 in my_tuple" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 20, 226 | "metadata": { 227 | "collapsed": false 228 | }, 229 | "outputs": [ 230 | { 231 | "data": { 232 | "text/plain": [ 233 | "({'dict_key': 'dict_val'}, [1, 2, 3])" 234 | ] 235 | }, 236 | "execution_count": 20, 237 | "metadata": {}, 238 | "output_type": "execute_result" 239 | } 240 | ], 241 | "source": [ 242 | "my_tuple[2:]" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "metadata": {}, 248 | "source": [ 249 | "## One element tuple" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 21, 255 | "metadata": { 256 | "collapsed": true 257 | }, 258 | "outputs": [], 259 | "source": [ 260 | "one_variable_tuple = (\"item1\")" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 22, 266 | "metadata": { 267 | "collapsed": false 268 | }, 269 | "outputs": [ 270 | { 271 | "data": { 272 | "text/plain": [ 273 | "'item1'" 274 | ] 275 | }, 276 | "execution_count": 22, 277 | "metadata": {}, 278 | "output_type": "execute_result" 279 | } 280 | ], 281 | "source": [ 282 | "one_variable_tuple" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 23, 288 | "metadata": { 289 | "collapsed": false 290 | }, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "str" 296 | ] 297 | }, 298 | "execution_count": 23, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "type(one_variable_tuple)" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": 24, 310 | "metadata": { 311 | "collapsed": true 312 | }, 313 | "outputs": [], 314 | "source": [ 315 | "one_variable_tuple2 = (\"item2\")," 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 25, 321 | "metadata": { 322 | "collapsed": false 323 | }, 324 | "outputs": [ 325 | { 326 | "data": { 327 | "text/plain": [ 328 | "('item2',)" 329 | ] 330 | }, 331 | "execution_count": 25, 332 | "metadata": {}, 333 | "output_type": "execute_result" 334 | } 335 | ], 336 | "source": [ 337 | "one_variable_tuple2" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 26, 343 | "metadata": { 344 | "collapsed": false 345 | }, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "tuple" 351 | ] 352 | }, 353 | "execution_count": 26, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "type(one_variable_tuple2)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "## When to use a tuple? \n", 367 | "- faster than a list\n", 368 | "- if you're not going to change a list, use a tuple" 369 | ] 370 | } 371 | ], 372 | "metadata": { 373 | "kernelspec": { 374 | "display_name": "Python 3", 375 | "language": "python", 376 | "name": "python3" 377 | }, 378 | "language_info": { 379 | "codemirror_mode": { 380 | "name": "ipython", 381 | "version": 3 382 | }, 383 | "file_extension": ".py", 384 | "mimetype": "text/x-python", 385 | "name": "python", 386 | "nbconvert_exporter": "python", 387 | "pygments_lexer": "ipython3", 388 | "version": "3.5.2" 389 | } 390 | }, 391 | "nbformat": 4, 392 | "nbformat_minor": 2 393 | } 394 | -------------------------------------------------------------------------------- /Module5/3_tuples.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Tuples\n", 8 | "- Can store any combination of data types\n", 9 | "- immutable\n", 10 | "- sequence of values, separated by commas" 11 | ] 12 | }, 13 | { 14 | "cell_type": "code", 15 | "execution_count": 11, 16 | "metadata": { 17 | "collapsed": false 18 | }, 19 | "outputs": [], 20 | "source": [ 21 | "my_tuple = (1,\"stuff\", {\"dict_key\": \"dict_val\"}, [1,2,3])" 22 | ] 23 | }, 24 | { 25 | "cell_type": "code", 26 | "execution_count": 12, 27 | "metadata": { 28 | "collapsed": false 29 | }, 30 | "outputs": [ 31 | { 32 | "data": { 33 | "text/plain": [ 34 | "(1, 'stuff', {'dict_key': 'dict_val'}, [1, 2, 3])" 35 | ] 36 | }, 37 | "execution_count": 12, 38 | "metadata": {}, 39 | "output_type": "execute_result" 40 | } 41 | ], 42 | "source": [ 43 | "my_tuple" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Access tuple items by index" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 13, 56 | "metadata": { 57 | "collapsed": false 58 | }, 59 | "outputs": [ 60 | { 61 | "data": { 62 | "text/plain": [ 63 | "{'dict_key': 'dict_val'}" 64 | ] 65 | }, 66 | "execution_count": 13, 67 | "metadata": {}, 68 | "output_type": "execute_result" 69 | } 70 | ], 71 | "source": [ 72 | "my_tuple[2]" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": 14, 78 | "metadata": { 79 | "collapsed": false 80 | }, 81 | "outputs": [ 82 | { 83 | "data": { 84 | "text/plain": [ 85 | "dict_values(['dict_val'])" 86 | ] 87 | }, 88 | "execution_count": 14, 89 | "metadata": {}, 90 | "output_type": "execute_result" 91 | } 92 | ], 93 | "source": [ 94 | "my_tuple[2].values()" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": {}, 100 | "source": [ 101 | "## Iterate through tuple items" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 15, 107 | "metadata": { 108 | "collapsed": false 109 | }, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "1\n", 116 | "stuff\n", 117 | "{'dict_key': 'dict_val'}\n", 118 | "[1, 2, 3]\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "for item in my_tuple:\n", 124 | " print(item)" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 16, 130 | "metadata": { 131 | "collapsed": false 132 | }, 133 | "outputs": [ 134 | { 135 | "name": "stdout", 136 | "output_type": "stream", 137 | "text": [ 138 | "0 1\n", 139 | "1 stuff\n", 140 | "2 {'dict_key': 'dict_val'}\n", 141 | "3 [1, 2, 3]\n" 142 | ] 143 | } 144 | ], 145 | "source": [ 146 | "for x,y in enumerate(my_tuple):\n", 147 | " print(x,y)" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "## Tuple operations" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 17, 160 | "metadata": { 161 | "collapsed": false 162 | }, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "4" 168 | ] 169 | }, 170 | "execution_count": 17, 171 | "metadata": {}, 172 | "output_type": "execute_result" 173 | } 174 | ], 175 | "source": [ 176 | "len(my_tuple)" 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 18, 182 | "metadata": { 183 | "collapsed": false 184 | }, 185 | "outputs": [ 186 | { 187 | "data": { 188 | "text/plain": [ 189 | "True" 190 | ] 191 | }, 192 | "execution_count": 18, 193 | "metadata": {}, 194 | "output_type": "execute_result" 195 | } 196 | ], 197 | "source": [ 198 | "1 in my_tuple" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 19, 204 | "metadata": { 205 | "collapsed": false 206 | }, 207 | "outputs": [ 208 | { 209 | "data": { 210 | "text/plain": [ 211 | "False" 212 | ] 213 | }, 214 | "execution_count": 19, 215 | "metadata": {}, 216 | "output_type": "execute_result" 217 | } 218 | ], 219 | "source": [ 220 | "2 in my_tuple" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": 20, 226 | "metadata": { 227 | "collapsed": false 228 | }, 229 | "outputs": [ 230 | { 231 | "data": { 232 | "text/plain": [ 233 | "({'dict_key': 'dict_val'}, [1, 2, 3])" 234 | ] 235 | }, 236 | "execution_count": 20, 237 | "metadata": {}, 238 | "output_type": "execute_result" 239 | } 240 | ], 241 | "source": [ 242 | "my_tuple[2:]" 243 | ] 244 | }, 245 | { 246 | "cell_type": "markdown", 247 | "metadata": {}, 248 | "source": [ 249 | "## One element tuple" 250 | ] 251 | }, 252 | { 253 | "cell_type": "code", 254 | "execution_count": 21, 255 | "metadata": { 256 | "collapsed": true 257 | }, 258 | "outputs": [], 259 | "source": [ 260 | "one_variable_tuple = (\"item1\")" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 22, 266 | "metadata": { 267 | "collapsed": false 268 | }, 269 | "outputs": [ 270 | { 271 | "data": { 272 | "text/plain": [ 273 | "'item1'" 274 | ] 275 | }, 276 | "execution_count": 22, 277 | "metadata": {}, 278 | "output_type": "execute_result" 279 | } 280 | ], 281 | "source": [ 282 | "one_variable_tuple" 283 | ] 284 | }, 285 | { 286 | "cell_type": "code", 287 | "execution_count": 23, 288 | "metadata": { 289 | "collapsed": false 290 | }, 291 | "outputs": [ 292 | { 293 | "data": { 294 | "text/plain": [ 295 | "str" 296 | ] 297 | }, 298 | "execution_count": 23, 299 | "metadata": {}, 300 | "output_type": "execute_result" 301 | } 302 | ], 303 | "source": [ 304 | "type(one_variable_tuple)" 305 | ] 306 | }, 307 | { 308 | "cell_type": "code", 309 | "execution_count": 24, 310 | "metadata": { 311 | "collapsed": true 312 | }, 313 | "outputs": [], 314 | "source": [ 315 | "one_variable_tuple2 = (\"item2\")," 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 25, 321 | "metadata": { 322 | "collapsed": false 323 | }, 324 | "outputs": [ 325 | { 326 | "data": { 327 | "text/plain": [ 328 | "('item2',)" 329 | ] 330 | }, 331 | "execution_count": 25, 332 | "metadata": {}, 333 | "output_type": "execute_result" 334 | } 335 | ], 336 | "source": [ 337 | "one_variable_tuple2" 338 | ] 339 | }, 340 | { 341 | "cell_type": "code", 342 | "execution_count": 26, 343 | "metadata": { 344 | "collapsed": false 345 | }, 346 | "outputs": [ 347 | { 348 | "data": { 349 | "text/plain": [ 350 | "tuple" 351 | ] 352 | }, 353 | "execution_count": 26, 354 | "metadata": {}, 355 | "output_type": "execute_result" 356 | } 357 | ], 358 | "source": [ 359 | "type(one_variable_tuple2)" 360 | ] 361 | }, 362 | { 363 | "cell_type": "markdown", 364 | "metadata": {}, 365 | "source": [ 366 | "## When to use a tuple? \n", 367 | "- faster than a list\n", 368 | "- if you're not going to change a list, use a tuple" 369 | ] 370 | } 371 | ], 372 | "metadata": { 373 | "kernelspec": { 374 | "display_name": "Python 3", 375 | "language": "python", 376 | "name": "python3" 377 | }, 378 | "language_info": { 379 | "codemirror_mode": { 380 | "name": "ipython", 381 | "version": 3 382 | }, 383 | "file_extension": ".py", 384 | "mimetype": "text/x-python", 385 | "name": "python", 386 | "nbconvert_exporter": "python", 387 | "pygments_lexer": "ipython3", 388 | "version": "3.5.2" 389 | } 390 | }, 391 | "nbformat": 4, 392 | "nbformat_minor": 2 393 | } 394 | -------------------------------------------------------------------------------- /Module2/4_String_Formatting.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "## String Formatting\n", 8 | "Now that you've seen how to concatenate strings, you can learn an even better way to combine strings. " 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "### Concatenating Strings" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 3, 21 | "metadata": { 22 | "collapsed": true 23 | }, 24 | "outputs": [], 25 | "source": [ 26 | "a = \"hello \"\n", 27 | "b = \"world\"\n", 28 | "c = \"!\"" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 4, 34 | "metadata": { 35 | "collapsed": false 36 | }, 37 | "outputs": [ 38 | { 39 | "data": { 40 | "text/plain": [ 41 | "'hello world!'" 42 | ] 43 | }, 44 | "execution_count": 4, 45 | "metadata": {}, 46 | "output_type": "execute_result" 47 | } 48 | ], 49 | "source": [ 50 | "a + b + c" 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "### Python's Format Method\n", 58 | "Python has powerful methods for building and manipulating strings. This can be very handy for parsing input and output. " 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "#### Positional String Formatting" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": 5, 71 | "metadata": { 72 | "collapsed": true 73 | }, 74 | "outputs": [], 75 | "source": [ 76 | "first_name = 'Summer'\n", 77 | "middle_name = 'Rae'\n", 78 | "last_name = 'Elsaady'\n", 79 | "\n", 80 | "user_name = \"{} {} {}\".format(first_name, middle_name, last_name)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 6, 86 | "metadata": { 87 | "collapsed": false 88 | }, 89 | "outputs": [ 90 | { 91 | "name": "stdout", 92 | "output_type": "stream", 93 | "text": [ 94 | "Summer Rae Elsaady\n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "print(user_name)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "#### Named Formatting" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 9, 112 | "metadata": { 113 | "collapsed": true 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "user_name2 = \"{first} {middle} {last}\".format(first=first_name, \n", 118 | " middle=middle_name, \n", 119 | " last=last_name)" 120 | ] 121 | }, 122 | { 123 | "cell_type": "code", 124 | "execution_count": 10, 125 | "metadata": { 126 | "collapsed": false 127 | }, 128 | "outputs": [ 129 | { 130 | "name": "stdout", 131 | "output_type": "stream", 132 | "text": [ 133 | "Summer Rae Elsaady\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "print(user_name2)" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "#### Padding Strings" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": 11, 151 | "metadata": { 152 | "collapsed": false 153 | }, 154 | "outputs": [ 155 | { 156 | "data": { 157 | "text/plain": [ 158 | "' test'" 159 | ] 160 | }, 161 | "execution_count": 11, 162 | "metadata": {}, 163 | "output_type": "execute_result" 164 | } 165 | ], 166 | "source": [ 167 | "'{:>10}'.format('test')" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 12, 173 | "metadata": { 174 | "collapsed": false 175 | }, 176 | "outputs": [ 177 | { 178 | "data": { 179 | "text/plain": [ 180 | "' test'" 181 | ] 182 | }, 183 | "execution_count": 12, 184 | "metadata": {}, 185 | "output_type": "execute_result" 186 | } 187 | ], 188 | "source": [ 189 | "'{:>5}'.format('test')" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": 13, 195 | "metadata": { 196 | "collapsed": false 197 | }, 198 | "outputs": [ 199 | { 200 | "data": { 201 | "text/plain": [ 202 | "'test '" 203 | ] 204 | }, 205 | "execution_count": 13, 206 | "metadata": {}, 207 | "output_type": "execute_result" 208 | } 209 | ], 210 | "source": [ 211 | "'{:<10}'.format('test')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 14, 217 | "metadata": { 218 | "collapsed": false 219 | }, 220 | "outputs": [ 221 | { 222 | "data": { 223 | "text/plain": [ 224 | "'test '" 225 | ] 226 | }, 227 | "execution_count": 14, 228 | "metadata": {}, 229 | "output_type": "execute_result" 230 | } 231 | ], 232 | "source": [ 233 | "'{:<5}'.format('test')" 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": {}, 239 | "source": [ 240 | "#### Aligning Strings" 241 | ] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": 15, 246 | "metadata": { 247 | "collapsed": false 248 | }, 249 | "outputs": [ 250 | { 251 | "data": { 252 | "text/plain": [ 253 | "'test '" 254 | ] 255 | }, 256 | "execution_count": 15, 257 | "metadata": {}, 258 | "output_type": "execute_result" 259 | } 260 | ], 261 | "source": [ 262 | "'{:10}'.format('test')" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 16, 268 | "metadata": { 269 | "collapsed": false 270 | }, 271 | "outputs": [ 272 | { 273 | "data": { 274 | "text/plain": [ 275 | "'test______'" 276 | ] 277 | }, 278 | "execution_count": 16, 279 | "metadata": {}, 280 | "output_type": "execute_result" 281 | } 282 | ], 283 | "source": [ 284 | "'{:_<10}'.format('test')" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 17, 290 | "metadata": { 291 | "collapsed": false 292 | }, 293 | "outputs": [ 294 | { 295 | "data": { 296 | "text/plain": [ 297 | "'test******'" 298 | ] 299 | }, 300 | "execution_count": 17, 301 | "metadata": {}, 302 | "output_type": "execute_result" 303 | } 304 | ], 305 | "source": [ 306 | "'{:*<10}'.format('test')" 307 | ] 308 | }, 309 | { 310 | "cell_type": "code", 311 | "execution_count": 20, 312 | "metadata": { 313 | "collapsed": false 314 | }, 315 | "outputs": [ 316 | { 317 | "data": { 318 | "text/plain": [ 319 | "' test '" 320 | ] 321 | }, 322 | "execution_count": 20, 323 | "metadata": {}, 324 | "output_type": "execute_result" 325 | } 326 | ], 327 | "source": [ 328 | "'{:^10}'.format('test')" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "metadata": {}, 334 | "source": [ 335 | "#### Truncating Strings" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 21, 341 | "metadata": { 342 | "collapsed": false 343 | }, 344 | "outputs": [ 345 | { 346 | "data": { 347 | "text/plain": [ 348 | "'xylop'" 349 | ] 350 | }, 351 | "execution_count": 21, 352 | "metadata": {}, 353 | "output_type": "execute_result" 354 | } 355 | ], 356 | "source": [ 357 | "'{:.5}'.format('xylophone')" 358 | ] 359 | }, 360 | { 361 | "cell_type": "code", 362 | "execution_count": 22, 363 | "metadata": { 364 | "collapsed": false 365 | }, 366 | "outputs": [ 367 | { 368 | "data": { 369 | "text/plain": [ 370 | "'xylopho'" 371 | ] 372 | }, 373 | "execution_count": 22, 374 | "metadata": {}, 375 | "output_type": "execute_result" 376 | } 377 | ], 378 | "source": [ 379 | "'{:.7}'.format('xylophone')" 380 | ] 381 | }, 382 | { 383 | "cell_type": "markdown", 384 | "metadata": {}, 385 | "source": [ 386 | "### More information\n", 387 | "https://pyformat.info/#simple" 388 | ] 389 | }, 390 | { 391 | "cell_type": "code", 392 | "execution_count": null, 393 | "metadata": { 394 | "collapsed": true 395 | }, 396 | "outputs": [], 397 | "source": [] 398 | } 399 | ], 400 | "metadata": { 401 | "kernelspec": { 402 | "display_name": "Python 3", 403 | "language": "python", 404 | "name": "python3" 405 | }, 406 | "language_info": { 407 | "codemirror_mode": { 408 | "name": "ipython", 409 | "version": 3 410 | }, 411 | "file_extension": ".py", 412 | "mimetype": "text/x-python", 413 | "name": "python", 414 | "nbconvert_exporter": "python", 415 | "pygments_lexer": "ipython3", 416 | "version": "3.5.2" 417 | } 418 | }, 419 | "nbformat": 4, 420 | "nbformat_minor": 2 421 | } 422 | --------------------------------------------------------------------------------