├── _config.yml ├── Unit 09 Exam Statistics ├── 01 Review │ ├── 3-Review.py │ ├── 1-Lets look at those grades.py │ └── 2-Print those grades.py ├── 02 The average grade │ ├── 6-Review.py │ ├── 4-The sum of scores.py │ └── 5-Computing the Average.py ├── 03 Do the grades vary? │ ├── 7-The Variance.py │ ├── 8-Standard Deviation.py │ └── 9-Review.py └── examstats.py ├── Unit 01 Python Syntax ├── 02 Tip Calculator │ ├── 2-The tax.py │ ├── 1-The Meal.py │ ├── 3-The tip.py │ ├── 4-Reassign in a single line.py │ └── 5-The total.py └── 01 Python Syntax │ ├── Comments │ ├── Multi-Lines Comment.py │ └── Single Line Comments.py │ ├── Varibles and Data Types │ ├── welcome.py │ ├── Variables.py │ ├── Booleans.py │ └── Youve-been-reassigned.py │ ├── Whitespace and Statements │ ├── a matter of interpretation.py │ ├── whiteSpace.py │ └── whitespace means right space.py │ ├── Math Operations │ ├── Modulo.py │ ├── math.py │ └── Exponantiation.py │ └── Review │ └── Bringing It All Together.py ├── Unit 03 Conditionals and Control Flow ├── 02 PygLatin │ ├── PygLatin PART2 │ │ ├── 7-Ay B C.py │ │ ├── 8-Word up.py │ │ ├── 9-Move it on back.py │ │ ├── 10-Engind up.py │ │ └── 11-Testing is this thing on.py │ └── PygLatin PART1 │ │ ├── 2-Ahoy.py │ │ ├── 1-Brake it Down.py │ │ ├── 3-Input.py │ │ ├── 4-Check yourself.py │ │ ├── 6-Pop Quizz.py │ │ └── 5-Check yourself some more.py └── 01 Conditionals & Control Flow │ ├── Boolean Operators │ ├── 8-Not.py │ ├── 9-This and That.py │ ├── 7-Or.py │ ├── 6-And.py │ ├── 5-To be or not To be.py │ └── 10-Min 'n' match.py │ ├── If, Else and Elif │ ├── 12-If youre having.py │ ├── 11-Conditional Statement Syntax.py │ ├── 14-I got 99 problems but a switch aint one.py │ └── 13-else problems, I feel bad for you son.py │ ├── Comparators │ ├── 4-How the talbes have Turned.py │ ├── 3-Compare Closier.py │ └── 2-Compare Closely.py │ ├── Review │ └── 15-The big If.py │ └── Introduction to Control Flow │ └── 1-Go with the Flow.py ├── Unit 07 Lists and Functions ├── 02 Battleship │ ├── Dont Sinc my Battleship │ │ ├── 1-Welcome to Battleship.py │ │ ├── 2-Getting Our Feet Wet.py │ │ ├── 3-Make a List.py │ │ ├── 4-Check it Twice.py │ │ ├── 5-Custom Print.py │ │ ├── 6-Printing Pretty.py │ │ ├── 7-Hide.py │ │ ├── 8-And Seek.py │ │ └── 9-It's Not Cheating—It's Debugging.py │ ├── You Sunk my Battleship │ │ ├── 16-Game Over.py │ │ ├── 15-Play it, Sam.py │ │ ├── 18-To Your Battle Stations.py │ │ └── 17-A Real Win.py │ └── Hit or Miss │ │ ├── 10-You Win.py │ │ ├── 11-Danger, Will Robinson.py │ │ ├── 12-Bad Aim.py │ │ ├── 13-Not Again.py │ │ └── 14-Test Run.py └── 01 Lists and Functions │ ├── List Recap │ ├── 1-List accessing.py │ ├── 3-Appending to a list.py │ ├── 2-List element modification.py │ └── 4-Removing elements from lists.py │ ├── Function Recap │ ├── 5-Changing the functionality of a function.py │ ├── 7-Strings in Functions.py │ └── 6-More than one Argument.py │ ├── Introdution to using Functions with Lists │ ├── 8-Passing a list to a Function.py │ ├── 9-Using an element from a list in a function.py │ ├── 10-Modifying an element of a list in a function.py │ └── 11-List manipulation in functions.py │ ├── Using the entire list in a Function │ ├── 12-Printing out a list item by item in a function.py │ ├── 14-Passing a range into a function.py │ ├── 15-Iterating over a list in a function.py │ ├── 13-Modifying each element in a list in a function.py │ └── 16-Using strings in lists in functions.py │ └── Using Lists of Lists in Functions │ ├── 17-Using two lists as two arguments in a function.py │ └── 18-Using a list of lists in a function.py ├── Unit 08 Loops ├── 02 Practice makes perfect │ ├── Fun with Numbers │ │ ├── 1-Practice! Practice, Practice!.py │ │ ├── 2-is_even.py │ │ ├── 5-Factorial.py │ │ ├── 3-is_int.py │ │ ├── 4-digit_sum.py │ │ ├── 6-is_prime.py │ │ └── 6-is_prime using for loop.py │ ├── Listing your problems │ │ ├── 13-Product.py │ │ ├── 12-purify.py │ │ ├── 14-Remove_duplicates.py │ │ ├── 15-Median.py │ │ └── 11-Count.py │ └── String it together │ │ ├── 7-Reverse.py │ │ ├── 8-Anti_vowels.py │ │ ├── 10-censor.py │ │ └── 9-scrabble_score.py └── 01 Loops │ ├── For Loops │ ├── 9-for your Health.py │ ├── 11-For your Strings.py │ ├── 10-For your hobbies.py │ ├── 13-For your lists.py │ └── 12-For your A.py │ └── Step Up 'For's │ ├── While Loops │ ├── 6-Break.py │ ├── 2-Condition.py │ ├── 5-Infinite Loops.py │ ├── 3-While You're at it.py │ ├── 1-While you're here.py │ ├── 4-Simple Errors.py │ ├── 7-While and Else.py │ └── 8-Your own While and Else.py │ ├── 14-Looping over a Dictionary.py │ ├── 15-Counting as you go.py │ ├── 19-Create your own.py │ ├── 16-Multiple Lists.py │ ├── 17-For, Else.py │ └── 18-Change it Up.py ├── Unit 04 Functions ├── 01 Functions │ ├── Review │ │ ├── 18-Modules.py │ │ ├── 19-Builtin Functions.py │ │ └── 17-Functions.py │ ├── Built In Functions │ │ ├── 15-abs.py │ │ ├── 13-max.py │ │ ├── 14-min.py │ │ ├── 16-type.py │ │ └── 12-On beyond Strings.py │ ├── Importing Modules │ │ ├── 7-I know Kung Fu.py │ │ ├── 10-Universal Imports.py │ │ ├── 8-Generic Imports.py │ │ ├── 9-Function Imports.py │ │ └── 11-Here be Dragons.py │ ├── Function Syntax │ │ ├── 5-Functions and calling Functions.py │ │ ├── 4-Parameters and Arguments.py │ │ ├── 6-Practice Makes perfect.py │ │ ├── 3-Call and Response.py │ │ └── 2- Function Junction.py │ └── Introduction to Functions │ │ └── 1-What good are functions.py └── 02 Taking a Vacation │ ├── Review of Functions │ └── 1-Before we begin.py │ └── Planes, Hotels and Automobiles │ ├── 2-Planning your trip.py │ ├── 3-Getting there.py │ ├── 4-Transportation.py │ ├── 5-Pull it together.py │ ├── 6-Hey, You never know.py │ └── 7-Plan your Trip.py ├── Unit 11 Introduction to Classes ├── 02 Classes │ ├── A review of Classes │ │ ├── 1-Class basics.py │ │ ├── 2-Create an instance of a class.py │ │ ├── 3-Class member variables.py │ │ ├── 4-Calling class member variables.py │ │ ├── 5-Initializing a class.py │ │ └── 6-Referring to member variables.py │ └── Using Classes │ │ ├── 11-Building useful classes.py │ │ ├── 7-Creating class methods.py │ │ ├── 8-Modifying member variables.py │ │ ├── 10-Overriding methods.py │ │ └── 9-Inheritance.py └── 01 Introduction to classes │ ├── Class Basics │ ├── 2-Class Syntax.py │ ├── 3-Classier Classes.py │ ├── 4-Lets Not Get Too Selfish.py │ ├── 5-Instantiating Your First Object.py │ └── 1-Why Use Classes.py │ ├── Review │ ├── 15-Class Basics.py │ ├── 16-Class It Up.py │ ├── 17-Instantiate an Object.py │ └── 18-Inheritance.py │ ├── Member Variables and Functions │ ├── 8-A Methodical Approach.py │ ├── 7-Class Scope.py │ ├── 9-They are Multiplying.py │ ├── 6-More on init and self.py │ └── 10-Its Not All Animals and Fruits.py │ └── Inheritance │ ├── 12-Inheritance Syntax.py │ ├── 13-Override.py │ ├── 11-Warning: Here Be Dragons.py │ └── 14-This Looks Like a Job For.py ├── Unit 12 File Input and Output ├── 01 Introduction to file I-O │ ├── 2-The open Function.py │ ├── 4-Reading.py │ ├── 3-Writing.py │ └── 1-See It to Believe It.py └── 02 The Devil's in the Details │ ├── 7-The with and as Keywords.py │ ├── 8-Try It Yourself.py │ ├── 9-Case Closed?.py │ ├── 6-PSA: Buffering Data.py │ └── 5-Reading Between the Lines.py ├── Unit 02 Strings and Console Output ├── 02 Date and Time │ ├── 1-The datetime Library.py │ ├── 2-Getting the current date and time.py │ ├── 4-Hot Date.py │ ├── 5-Pretty time.py │ ├── 6-Grand Finale.py │ └── 3-Extracting Information.py └── 01 Strings and Console Outputs │ ├── String Methonds │ ├── 5-String Methods.py │ ├── 6-lower().py │ ├── 7-upper().py │ ├── 9-Dot Notation.py │ └── 8-str().py │ ├── Strings │ ├── 1-Strings.py │ ├── 3-Escaping Characters.py │ ├── 2-Practice.py │ └── 4-Access by Index.py │ ├── Print │ ├── 10-Printing Strings.py │ └── 11-Printing Variables.py │ ├── Advanced Printing │ ├── 12-String Concatenation.py │ ├── 13-Explicit String Conversion.py │ ├── 14-String Formatting with, PART1.py │ └── 15-String Formatting with, PART 2.py │ └── Review │ └── 16-and now for something completely familiar.py ├── Unit 05 Lists & Dictionaries ├── 02 A Day at the Supermarket │ ├── Shopping Trip │ │ ├── 10-Shopping at the market.py │ │ ├── 11-Making a purchase.py │ │ ├── 12-Stocking Out.py │ │ └── 13-Lets Check out.py │ ├── Looping and lists │ │ ├── 1-beFOR we begin.py │ │ ├── 3-Control flow and Looping.py │ │ ├── 4-Lists + Functions.py │ │ ├── 5-String Looping.py │ │ └── 2-This is KEY.py │ └── Owning a Store │ │ ├── 6-Your own Store.py │ │ ├── 7-Investing in Stock.py │ │ ├── 8-Keeping track of the Produce.py │ │ └── 9-Something of value.py └── 01 Python Lists and Dictionaries │ ├── Dictionaries │ ├── 13-Removing a few Things.py │ ├── 10-This next part is key.py │ ├── 11-New Entries.py │ ├── 12-Changing your mind.py │ └── 14-Its dangerous to go alone!Take this.py │ ├── Lists Capabilities and Functions │ ├── 8-For one and All.py │ ├── 6-Slicing Lists and Strings.py │ ├── 7-Mantaining Order.py │ ├── 5-List Slicing.py │ ├── 9-More with for.py │ └── 4-Late Arrivals and List length.py │ └── Lists │ ├── 2-Access by Index.py │ ├── 3-New Neibors.py │ └── 1-Introduction to Lists.py ├── Unit 10 Advanced Topics in Python ├── 02 Introduction to Bitwise Operators │ ├── The Bitwise Operators │ │ ├── 9-This XOR That?.py │ │ ├── 7-A BIT of This AND That.py │ │ ├── 8-A BIT of This OR That.py │ │ ├── 10-See? This is NOT That Hard!.py │ │ └── 6-Slide to the Left! Slide to the Right!.py │ ├── A bit more Complicated │ │ ├── 12-Turn It On.py │ │ ├── 13-Just Flip Out.py │ │ ├── 14-Slip and Slide .py │ │ └── 11-The Man Behind the Bit Mask.py │ └── Binary representation │ │ ├── 4-The bin() Function.py │ │ ├── 1-Just a Little BIT.py │ │ ├── 5-int()'s Second Parameter.py │ │ ├── 3-I Can Count to 1100!.py │ │ └── 2-Lesson I0: The Base 2 Number System.py └── 01 Advanced Topics in Python │ ├── Lambdas │ ├── 14-Try It.py │ ├── 13-Lambda Syntax.py │ └── 12-Anonymous Functions.py │ ├── List Comprehentions │ ├── 4-Building Lists.py │ ├── 6-Now You Try.py │ └── 5-List Comprehension Syntax.py │ ├── Review │ ├── 17-List Slicing.py │ ├── 16-Comprehending Comprehensions.py │ ├── 18-Lambda Expressions.py │ └── 15-Iterating Over Dictionaries.py │ ├── List Slicing │ ├── 8-Omitting Indices.py │ ├── 9-Reversing a List.py │ ├── 7-List Slicing Syntax.py │ ├── 10-Stride Length.py │ └── 11-Practice Makes Perfect.py │ └── Iteration Nation │ ├── 1-Iterators for Dictionaries.py │ ├── 2-keys and values.py │ └── 3-The in Operator.py ├── Unit 06 Student Becomes the Teacher ├── 01 Good Morning Class │ ├── 1-Lesson number one.py │ ├── 2-Whats the score.py │ ├── 3-Put it together.py │ └── 4-For the Record.py └── 02 Just Average │ ├── 5-Its okay to be average.py │ ├── 6-Just weight and see.py │ ├── 7-Sending a Letter.py │ ├── 9-How is everything doing.py │ └── 8-Part of the Whole.py ├── .gitignore └── README.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/01 Review/3-Review.py: -------------------------------------------------------------------------------- 1 | print "Let's compute some stats!" 2 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/02 Tip Calculator/2-The tax.py: -------------------------------------------------------------------------------- 1 | meal = 44.50 2 | tax = 0.0675 3 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART2/7-Ay B C.py: -------------------------------------------------------------------------------- 1 | pyg = 'ay' 2 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/1-Welcome to Battleship.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/1-Practice! Practice, Practice!.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/2-Ahoy.py: -------------------------------------------------------------------------------- 1 | print 'Pig Latin' 2 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/02 The average grade/6-Review.py: -------------------------------------------------------------------------------- 1 | print "Time to conquer the variance!" 2 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Review/18-Modules.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print math.sqrt(13689) 4 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Comments/Multi-Lines Comment.py: -------------------------------------------------------------------------------- 1 | """ eai jovem 2 | blz 3 | """ 4 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Varibles and Data Types/welcome.py: -------------------------------------------------------------------------------- 1 | print "Welcome to Python!" 2 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/2-Getting Our Feet Wet.py: -------------------------------------------------------------------------------- 1 | board = [] 2 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Built In Functions/15-abs.py: -------------------------------------------------------------------------------- 1 | 2 | absolute = abs(-42) 3 | 4 | print absolute 5 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Comments/Single Line Comments.py: -------------------------------------------------------------------------------- 1 | # haha 2 | 3 | mysterious_variable = 42 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Review of Functions/1-Before we begin.py: -------------------------------------------------------------------------------- 1 | def answer(): 2 | return 42 3 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/1-Class basics.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | pass 3 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/01 Introduction to file I-O/2-The open Function.py: -------------------------------------------------------------------------------- 1 | my_file = open("output.txt", "r+") 2 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Varibles and Data Types/Variables.py: -------------------------------------------------------------------------------- 1 | # Write your code below! 2 | my_variable = 10 3 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Whitespace and Statements/a matter of interpretation.py: -------------------------------------------------------------------------------- 1 | spam = True 2 | eggs = False 3 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Class Basics/2-Class Syntax.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | pass 3 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/02 Tip Calculator/1-The Meal.py: -------------------------------------------------------------------------------- 1 | # Assign the variable meal the value 44.50 on line 3! 2 | 3 | meal = 44.50 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Importing Modules/7-I know Kung Fu.py: -------------------------------------------------------------------------------- 1 | # Ask Python to print sqrt(25) on line 3. 2 | 3 | print sqrt(25) 4 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/For Loops/9-for your Health.py: -------------------------------------------------------------------------------- 1 | print "Counting..." 2 | 3 | for i in range(20): 4 | print i 5 | 6 | 7 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/1-The datetime Library.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | print datetime.datetime 3 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Shopping Trip/10-Shopping at the market.py: -------------------------------------------------------------------------------- 1 | groceries = ["banana","orange","apple"] 2 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/The Bitwise Operators/9-This XOR That?.py: -------------------------------------------------------------------------------- 1 | print bin(0b1110 ^ 0b101) 2 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Whitespace and Statements/whiteSpace.py: -------------------------------------------------------------------------------- 1 | def spam(): 2 | eggs = 12 3 | return eggs 4 | 5 | print spam() 6 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/List Recap/1-List accessing.py: -------------------------------------------------------------------------------- 1 | n = [1, 3, 5] 2 | 3 | # Add your code below 4 | print n[1] 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/String Methonds/5-String Methods.py: -------------------------------------------------------------------------------- 1 | parrot = "Norwegian Blue" 2 | print len(parrot) 3 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/The Bitwise Operators/7-A BIT of This AND That.py: -------------------------------------------------------------------------------- 1 | print bin(0b1110 & 0b101) 2 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/The Bitwise Operators/8-A BIT of This OR That.py: -------------------------------------------------------------------------------- 1 | print bin(0b1110 | 0b101) 2 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/2-Create an instance of a class.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | pass 3 | my_car = Car() 4 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/01 Introduction to file I-O/4-Reading.py: -------------------------------------------------------------------------------- 1 | my_file = open("output.txt", "r") 2 | print my_file.read() 3 | my_file.close() 4 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Math Operations/Modulo.py: -------------------------------------------------------------------------------- 1 | #Set spam equal to 1 using modulo on line 3! 2 | 3 | spam = 3 % 2 4 | 5 | print spam 6 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Review/Bringing It All Together.py: -------------------------------------------------------------------------------- 1 | #que pais 2 | monty = True 3 | python = 1.234 4 | monty_python = python ** 2 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/String Methonds/6-lower().py: -------------------------------------------------------------------------------- 1 | parrot = "Norwegian Blue" 2 | 3 | print parrot.lower() 4 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/String Methonds/7-upper().py: -------------------------------------------------------------------------------- 1 | parrot = "norwegian blue" 2 | 3 | print parrot.upper() 4 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Strings/1-Strings.py: -------------------------------------------------------------------------------- 1 | # Set the variable brian on line 3! 2 | 3 | brian = "Hello life!" 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Importing Modules/10-Universal Imports.py: -------------------------------------------------------------------------------- 1 | # Import *everything* from the math module on line 3! 2 | 3 | from math import * 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Importing Modules/8-Generic Imports.py: -------------------------------------------------------------------------------- 1 | # Ask Python to print sqrt(25) on line 3. 2 | import math 3 | print math.sqrt(25) 4 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/3-Class member variables.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | my_car = Car() 4 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/2-Getting the current date and time.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | now = datetime.now() 3 | print now 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Importing Modules/9-Function Imports.py: -------------------------------------------------------------------------------- 1 | # Import *just* the sqrt function from math on line 3! 2 | 3 | from math import sqrt 4 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/List Recap/3-Appending to a list.py: -------------------------------------------------------------------------------- 1 | n = [1, 3, 5] 2 | # Append the number 4 here 3 | n.append(4) 4 | print n 5 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/01 Review/1-Lets look at those grades.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | print "Grades:", grades 3 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/02 Tip Calculator/3-The tip.py: -------------------------------------------------------------------------------- 1 | # You're almost there! Assign the tip variable on line 5. 2 | 3 | meal = 44.50 4 | tax = 0.0675 5 | tip = 0.15 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Listing your problems/13-Product.py: -------------------------------------------------------------------------------- 1 | def product(x): 2 | t = 1 3 | for n in x: 4 | t *= n 5 | return t 6 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Class Basics/3-Classier Classes.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | def __init__(self): 3 | pass 4 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/02 The Devil's in the Details/7-The with and as Keywords.py: -------------------------------------------------------------------------------- 1 | with open("text.txt", "w") as textfile: 2 | textfile.write("Success!") 3 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/02 The Devil's in the Details/8-Try It Yourself.py: -------------------------------------------------------------------------------- 1 | with open("text.txt", "w") as my_file: 2 | my_file.write("Tretas dos Bronzetas") 3 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Math Operations/math.py: -------------------------------------------------------------------------------- 1 | # Set count_to equal to the sum of two big numbers 2 | 3 | count_to = 900 +988 4 | 5 | print count_to 6 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Whitespace and Statements/whitespace means right space.py: -------------------------------------------------------------------------------- 1 | def spam(): 2 | eggs = 12 3 | return eggs 4 | 5 | print spam() 6 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/2-Planning your trip.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/A bit more Complicated/12-Turn It On.py: -------------------------------------------------------------------------------- 1 | a = 0b10111011 2 | mask = 0b100 3 | print bin(a | mask) 4 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Math Operations/Exponantiation.py: -------------------------------------------------------------------------------- 1 | #Set eggs equal to 100 using exponentiation on line 3! 2 | 3 | eggs = 10 ** 2 4 | 5 | print eggs 6 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/List Recap/2-List element modification.py: -------------------------------------------------------------------------------- 1 | n = [1, 3, 5] 2 | # Do your multiplication here 3 | n[1] = n[1] * 5 4 | print n 5 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/You Sunk my Battleship/16-Game Over.py: -------------------------------------------------------------------------------- 1 | #adicionar ao final as seguintes linhas: 2 | if turn == 3: 3 | print "Game Over" 4 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/6-Break.py: -------------------------------------------------------------------------------- 1 | count = 0 2 | 3 | while True: 4 | print count 5 | count += 1 6 | if count >= 10: 7 | break 8 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/2-is_even.py: -------------------------------------------------------------------------------- 1 | def is_even(x): 2 | if x % 2 == 0: 3 | return True 4 | else: 5 | return False 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Lambdas/14-Try It.py: -------------------------------------------------------------------------------- 1 | squares = [x**2 for x in range(1,11)] 2 | print filter (lambda x: 30 <= x <= 70 , squares) 3 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/4-Hot Date.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | now = datetime.now() 3 | 4 | print '%s/%s/%s' % (now.year, now.month, now.day) 5 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Built In Functions/13-max.py: -------------------------------------------------------------------------------- 1 | # Set maximum to the max value of any set of numbers on line 3! 2 | 3 | maximum = max(3,5,10,2) 4 | 5 | print maximum 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/2-Condition.py: -------------------------------------------------------------------------------- 1 | loop_condition = True 2 | 3 | while loop_condition: 4 | print "I am a loop" 5 | loop_condition = False 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Comprehentions/4-Building Lists.py: -------------------------------------------------------------------------------- 1 | evens_to_50 = [i for i in range(51) if i % 2 == 0] 2 | print evens_to_50 3 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Review/17-List Slicing.py: -------------------------------------------------------------------------------- 1 | garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI" 2 | message = garbled[::-2] 3 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/02 Tip Calculator/4-Reassign in a single line.py: -------------------------------------------------------------------------------- 1 | # Reassign meal on line 7! 2 | 3 | meal = 44.50 4 | tax = 0.0675 5 | tip = 0.15 6 | 7 | meal = meal+ meal * tax 8 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Function Syntax/5-Functions and calling Functions.py: -------------------------------------------------------------------------------- 1 | def one_good_turn(n): 2 | return n + 1 3 | 4 | def deserves_another(n): 5 | return n + 3 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Comprehentions/6-Now You Try.py: -------------------------------------------------------------------------------- 1 | cubes_by_four = [x**3 for x in range(1,11) if (x**3)%4 == 0] 2 | print cubes_by_four 3 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/5-Pretty time.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | now = datetime.now() 3 | 4 | print '%s:%s:%s' % (now.hour, now.minute, now.second) 5 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Built In Functions/14-min.py: -------------------------------------------------------------------------------- 1 | # Set minimum to the min value of any set of numbers on line 3! 2 | 3 | minimum = min(-1,30,3,78,-22) 4 | 5 | print minimum 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/5-Infinite Loops.py: -------------------------------------------------------------------------------- 1 | count = 0 2 | 3 | while count < 10: # Add a colon 4 | print count 5 | # Increment count 6 | count += 1 7 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/4-Calling class member variables.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | my_car = Car() 4 | print my_car.condition 5 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/14-Looping over a Dictionary.py: -------------------------------------------------------------------------------- 1 | d = {'a': 'apple', 'b': 'berry', 'c': 'cherry'} 2 | 3 | for key in d: 4 | # Your code here! 5 | print key, d[key] 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/A bit more Complicated/13-Just Flip Out.py: -------------------------------------------------------------------------------- 1 | a = 0b11101110 2 | mask = 0b11111111 3 | result =(a^mask) 4 | print bin(result) 5 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/The Bitwise Operators/10-See? This is NOT That Hard!.py: -------------------------------------------------------------------------------- 1 | print ~1 2 | print ~2 3 | print ~3 4 | print ~42 5 | print ~123 6 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Print/10-Printing Strings.py: -------------------------------------------------------------------------------- 1 | """Tell Python to print "Monty Python" 2 | to the console on line 4!""" 3 | 4 | print "Monty Python" 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/String Methonds/9-Dot Notation.py: -------------------------------------------------------------------------------- 1 | ministry = "The Ministry of Silly Walks" 2 | 3 | print len(ministry) 4 | print ministry.upper() 5 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Looping and lists/1-beFOR we begin.py: -------------------------------------------------------------------------------- 1 | names = ["Adam","Alex","Mariah","Martine","Columbus"] 2 | 3 | for word in names: 4 | print word 5 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Lambdas/13-Lambda Syntax.py: -------------------------------------------------------------------------------- 1 | languages = ["HTML", "JavaScript", "Python", "Ruby"] 2 | print filter(lambda a: a == 'Python', languages) 3 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/Binary representation/4-The bin() Function.py: -------------------------------------------------------------------------------- 1 | print bin(1) 2 | print bin(2) 3 | print bin(3) 4 | print bin(4) 5 | print bin(5) 6 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/3-Make a List.py: -------------------------------------------------------------------------------- 1 | board = [] 2 | 3 | for loop in range(0, 5): 4 | treta = ["O"] * 5 5 | board.append(treta) 6 | print board 7 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/4-Check it Twice.py: -------------------------------------------------------------------------------- 1 | board = [] 2 | 3 | for loop in range(0, 5): 4 | treta = ["O"] * 5 5 | board.append(treta) 6 | print board 7 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Listing your problems/12-purify.py: -------------------------------------------------------------------------------- 1 | def purify(x): 2 | par=[] 3 | for i in x: 4 | if (i % 2 == 0): 5 | par.append(i) 6 | return par 7 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Slicing/8-Omitting Indices.py: -------------------------------------------------------------------------------- 1 | my_list = range(1, 11) # List of numbers 1 - 10 2 | 3 | # Add your code below! 4 | print my_list[::2] 5 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Slicing/9-Reversing a List.py: -------------------------------------------------------------------------------- 1 | my_list = range(1, 11) 2 | 3 | # Add your code below! 4 | backwards = my_list[::-1] 5 | print backwards 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Review/16-Comprehending Comprehensions.py: -------------------------------------------------------------------------------- 1 | threes_and_fives = [ x for x in range(1,16) if ((x%3==0) or (x%5==0))] 2 | print threes_and_fives 3 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Class Basics/4-Lets Not Get Too Selfish.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | def __init__(self, name): 3 | self.name = name 4 | pass 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Advanced Printing/12-String Concatenation.py: -------------------------------------------------------------------------------- 1 | # Print the concatenation of "Spam and eggs" on line 3! 2 | 3 | print "Spam " + "and " + "eggs" 4 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Advanced Printing/13-Explicit String Conversion.py: -------------------------------------------------------------------------------- 1 | # Turn 3.14 into a string on line 3! 2 | 3 | print "The value of pi is around " + str(3.14) 4 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Dictionaries/13-Removing a few Things.py: -------------------------------------------------------------------------------- 1 | backpack = ['xylophone', 'dagger', 'tent', 'bread loaf'] 2 | backpack.remove('dagger') 3 | print backpack 4 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Owning a Store/6-Your own Store.py: -------------------------------------------------------------------------------- 1 | prices = { 2 | "banana": 4, 3 | "apple": 2, 4 | "orange": 1.5, 5 | "pear": 3 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Function Recap/5-Changing the functionality of a function.py: -------------------------------------------------------------------------------- 1 | number = 5 2 | 3 | def my_function(x): 4 | return x * 3 5 | 6 | print my_function(number) 7 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/For Loops/11-For your Strings.py: -------------------------------------------------------------------------------- 1 | thing = "spam!" 2 | 3 | for c in thing: 4 | print c 5 | 6 | word = "eggs!" 7 | 8 | # Your code here! 9 | for a in word: 10 | print a 11 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/A bit more Complicated/14-Slip and Slide .py: -------------------------------------------------------------------------------- 1 | def flip_bit(number,n): 2 | result = number ^ (0b1 << (n-1)) 3 | return bin(result) 4 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Built In Functions/16-type.py: -------------------------------------------------------------------------------- 1 | # Print out the types of an integer, a float, 2 | # and a string on separate lines below. 3 | 4 | print type(3) 5 | print type(2.1) 6 | print type('no') 7 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Function Recap/7-Strings in Functions.py: -------------------------------------------------------------------------------- 1 | n = "Hello" 2 | # Your function here! 3 | def string_function(s): 4 | return s + 'world' 5 | print string_function(n) 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/For Loops/10-For your hobbies.py: -------------------------------------------------------------------------------- 1 | hobbies = [] 2 | 3 | # Add your code below! 4 | for a in range(3): 5 | i = raw_input('Select a hobbie') 6 | 7 | hobbies.append(i) 8 | print hobbies 9 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Slicing/7-List Slicing Syntax.py: -------------------------------------------------------------------------------- 1 | l = [i ** 2 for i in range(1, 11)] 2 | # Should be [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 3 | 4 | print l[2:9:2] 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/String Methonds/8-str().py: -------------------------------------------------------------------------------- 1 | """Declare and assign your variable on line 4, 2 | then call your method on line 5!""" 3 | 4 | pi = 3.14 5 | print str(pi) 6 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/8-For one and All.py: -------------------------------------------------------------------------------- 1 | my_list = [1,9,3,8,5,7] 2 | 3 | for number in my_list: 4 | # Your code here 5 | print 2*number 6 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Function Recap/6-More than one Argument.py: -------------------------------------------------------------------------------- 1 | m = 5 2 | n = 13 3 | # Add add_function here! 4 | def add_function(x, y): 5 | return x + y 6 | print add_function(m, n) 7 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Introdution to using Functions with Lists/8-Passing a list to a Function.py: -------------------------------------------------------------------------------- 1 | def list_function(x): 2 | return x 3 | 4 | n = [3, 5, 7] 5 | print list_function(n) 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/15-Counting as you go.py: -------------------------------------------------------------------------------- 1 | choices = ['pizza', 'pasta', 'salad', 'nachos'] 2 | 3 | print 'Your choices are:' 4 | for index, item in enumerate(choices): 5 | print index+1, item 6 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Listing your problems/14-Remove_duplicates.py: -------------------------------------------------------------------------------- 1 | def remove_duplicates(x): 2 | b = [] 3 | for a in x: 4 | if a not in b: 5 | b.append(a) 6 | return b 7 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Strings/3-Escaping Characters.py: -------------------------------------------------------------------------------- 1 | # The string below is broken. Fix it using the escape backslash! 2 | 3 | 'This isn\'t flying, this is falling with style!' 4 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/5-Factorial.py: -------------------------------------------------------------------------------- 1 | def factorial(x): 2 | if x == 1 or x == 0: 3 | print 1 4 | return 1 5 | else: 6 | return x*factorial(x - 1) 7 | 8 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Slicing/10-Stride Length.py: -------------------------------------------------------------------------------- 1 | to_one_hundred = range(101) 2 | # Add your code below! 3 | backwards_by_tens = to_one_hundred[::10] 4 | print backwards_by_tens 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/6-Grand Finale.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | now = datetime.now() 3 | 4 | print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year, now.hour, now.minute, now.second) 5 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Review/19-Builtin Functions.py: -------------------------------------------------------------------------------- 1 | def distance_from_zero(num): 2 | if type(num) == int or type(num) == float: 3 | no = abs(num) 4 | return no 5 | else: 6 | return 'Nope' 7 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Looping and lists/3-Control flow and Looping.py: -------------------------------------------------------------------------------- 1 | a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] 2 | for number in a: 3 | if number % 2 == 0: 4 | print number 5 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/1-Brake it Down.py: -------------------------------------------------------------------------------- 1 | def ral 2 | raw = raw_input('TELL ME a word in ENGRIXH').lower() 3 | if raw != str 4 | return 'NOOO, IN engrixs' 5 | ral 6 | 7 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/3-Input.py: -------------------------------------------------------------------------------- 1 | print 'Welcome to the Pig Latin Translator!' 2 | 3 | # Start coding here! 4 | 5 | original = raw_input('TELL ME a word in ENGRIXH:').lower() 6 | 7 | 8 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Review/17-Functions.py: -------------------------------------------------------------------------------- 1 | def shut_down(s): 2 | if s == "yes": 3 | return 'Shutting down' 4 | elif s == "no": 5 | return 'Shutdown aborted' 6 | else: 7 | return 'Sorry' 8 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Introdution to using Functions with Lists/9-Using an element from a list in a function.py: -------------------------------------------------------------------------------- 1 | def list_function(x): 2 | return x[1] 3 | 4 | n = [3, 5, 7] 5 | print list_function(n) 6 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Importing Modules/11-Here be Dragons.py: -------------------------------------------------------------------------------- 1 | import math # Imports the math module 2 | everything = dir(math) # Sets everything to a list of things from math 3 | print everything # Prints 'em all! 4 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/String it together/7-Reverse.py: -------------------------------------------------------------------------------- 1 | def reverse(text): 2 | TETO='' 3 | x=len(text) 4 | while(x>0): 5 | TETO=TETO+text[x-1] 6 | x=x-1 7 | print TETO 8 | return TETO 9 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Lambdas/12-Anonymous Functions.py: -------------------------------------------------------------------------------- 1 | my_list = range(16) 2 | print filter(lambda x: x % 3 == 0, my_list) 3 | 4 | #is the same as: 5 | def by_three(x): 6 | return x % 3 == 0 7 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Advanced Printing/14-String Formatting with, PART1.py: -------------------------------------------------------------------------------- 1 | string_1 = "Camelot" 2 | string_2 = "place" 3 | 4 | print "Let's not go to %s. 'Tis a silly %s." % (string_1, string_2) 5 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Review/16-and now for something completely familiar.py: -------------------------------------------------------------------------------- 1 | # Write your code below, starting on line 3! 2 | my_string = 'admin' 3 | print len(my_string) 4 | print my_string.upper() 5 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/A bit more Complicated/11-The Man Behind the Bit Mask.py: -------------------------------------------------------------------------------- 1 | def check_bit4(input): 2 | if input & 0b1000 > 0: 3 | return "on" 4 | else: 5 | return "off" 6 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/02 The Devil's in the Details/9-Case Closed?.py: -------------------------------------------------------------------------------- 1 | with open("text.txt", "w") as my_file: 2 | my_file.write("Tretas dos Bronzetas") 3 | if my_file.closed == False: 4 | my_file.close() 5 | print my_file.closed 6 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Iteration Nation/1-Iterators for Dictionaries.py: -------------------------------------------------------------------------------- 1 | my_dict = { 2 | "name": "Arthur", 3 | "age": 24, 4 | "color":"blue", 5 | "game":"PoE" 6 | } 7 | print my_dict.items() 8 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/19-Create your own.py: -------------------------------------------------------------------------------- 1 | Aline = ['danca', 'corre', 'platina', 'feeda'] 2 | 3 | for a in Aline: 4 | if a == 'feeda' or a == 'platina': 5 | print a, 'EOQ' 6 | 7 | else: 8 | print a, 'MENTIRA' 9 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Introdution to using Functions with Lists/10-Modifying an element of a list in a function.py: -------------------------------------------------------------------------------- 1 | def list_function(x): 2 | x[1] = x[1] + 3 3 | return x 4 | 5 | n = [3, 5, 7] 6 | print list_function(n) 7 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/For Loops/13-For your lists.py: -------------------------------------------------------------------------------- 1 | numbers = [7, 9, 12, 54, 99] 2 | 3 | print "This list contains: " 4 | 5 | for num in numbers: 6 | print num 7 | 8 | # Add your loop below! 9 | for num in numbers: 10 | print num ** 2 11 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Listing your problems/15-Median.py: -------------------------------------------------------------------------------- 1 | def median(a): 2 | a = sorted(a) 3 | b = len(a) 4 | if b%2 == 0: 5 | return (a[len(a)/2] + a[(len(a)/2) - 1]) / 2.0 6 | else: 7 | return a[(len(a)-1)/2] 8 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Slicing/11-Practice Makes Perfect.py: -------------------------------------------------------------------------------- 1 | to_21 = range(1,22) 2 | 3 | odds = to_21[::2] 4 | 5 | middle_third = to_21[7:14] 6 | 7 | print to_21 8 | print odds 9 | print middle_third 10 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Review/15-Class Basics.py: -------------------------------------------------------------------------------- 1 | class Triangle(object): 2 | def __init__(self, angle1, angle2, angle3): 3 | self.angle1 = angle1 4 | self.angle2 = angle2 5 | self.angle3 = angle3 6 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using the entire list in a Function/12-Printing out a list item by item in a function.py: -------------------------------------------------------------------------------- 1 | n = [3, 5, 7] 2 | 3 | def print_list(x): 4 | for i in range(0, len(x)): 5 | print x[i] 6 | 7 | print_list(n) 8 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using the entire list in a Function/14-Passing a range into a function.py: -------------------------------------------------------------------------------- 1 | def my_function(x): 2 | for i in range(0, len(x)): 3 | x[i] = x[i] * 2 4 | return x 5 | 6 | print my_function(range(3)) 7 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Iteration Nation/2-keys and values.py: -------------------------------------------------------------------------------- 1 | my_dict = { 2 | "name": "Arthur", 3 | "age": 24, 4 | "color":"blue", 5 | "game":"PoE" 6 | } 7 | print my_dict.keys() 8 | print my_dict.values() 9 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/3-While You're at it.py: -------------------------------------------------------------------------------- 1 | num = 1 2 | 3 | while num <= 10: # Fill in the condition 4 | x = num ** 2# Print num squared 5 | num = num + 1# Increment num (make sure to do this!) 6 | print x 7 | print num 8 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/3-is_int.py: -------------------------------------------------------------------------------- 1 | def is_int(x): 2 | if x - round(x) > 0: 3 | return False 4 | else: 5 | if x < 0 and x - round(x) < 0: 6 | return False 7 | else: 8 | return True 9 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/4-digit_sum.py: -------------------------------------------------------------------------------- 1 | def digit_sum(n): 2 | b = [] 3 | n = str(n) 4 | for a in n: 5 | a = int(a) 6 | b.append(a) 7 | return sum(b) 8 | print sum(b) 9 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Class Basics/5-Instantiating Your First Object.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | def __init__(self, name): 3 | self.name = name 4 | pass 5 | 6 | zebra = Animal("Jeffrey") 7 | print zebra.name 8 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/01 Introduction to file I-O/3-Writing.py: -------------------------------------------------------------------------------- 1 | my_list = [i**2 for i in range(1,11)] 2 | 3 | my_file = open("output.txt", "r+") 4 | 5 | # Add your code below! 6 | for item in my_list: 7 | my_file.write(str(item) + "\n") 8 | my_file.close() 9 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Varibles and Data Types/Booleans.py: -------------------------------------------------------------------------------- 1 | # Set the variables to the values listed in the instructions! 2 | 3 | my_int = 7 4 | my_float = 1.23 5 | my_bool = True 6 | 7 | print (my_int) 8 | print (my_float) 9 | print (my_bool) 10 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Print/11-Printing Variables.py: -------------------------------------------------------------------------------- 1 | """Assign the string "Ping!" to 2 | the variable the_machine_goes on 3 | line 5, then print it out on line 6!""" 4 | 5 | the_machine_goes = "Ping!" 6 | print the_machine_goes 7 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Introdution to using Functions with Lists/11-List manipulation in functions.py: -------------------------------------------------------------------------------- 1 | n = [3, 5, 7] 2 | # Add your function here 3 | def list_extender(lst): 4 | lst.append(9) 5 | return lst 6 | 7 | print list_extender(n) 8 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/1-While you're here.py: -------------------------------------------------------------------------------- 1 | count = 0 2 | 3 | if count <= 9: 4 | print "Hello, I am an if statement and count is", count 5 | 6 | while count <= 9: 7 | print "Hello, I am a while and count is", count 8 | count += 1 9 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Review/18-Lambda Expressions.py: -------------------------------------------------------------------------------- 1 | garbled = "IXXX aXXmX aXXXnXoXXXXXtXhXeXXXXrX sXXXXeXcXXXrXeXt mXXeXsXXXsXaXXXXXXgXeX!XX" 2 | message = filter (lambda letter: letter.replace ("X",""),garbled) 3 | 4 | print message 5 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/02 Tip Calculator/5-The total.py: -------------------------------------------------------------------------------- 1 | # Assign the variable total on line 8! 2 | 3 | meal = 44.50 4 | tax = 0.0675 5 | tip = 0.15 6 | 7 | meal = meal + meal * tax 8 | total = meal + meal*tip 9 | 10 | print meal 11 | print total 12 | print("%.2f" % total) 13 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/4-Simple Errors.py: -------------------------------------------------------------------------------- 1 | choice = raw_input('Enjoying the course? (y/n)') 2 | 3 | while (choice != "y" and choice != "n"): # Fill in the condition (before the colon) 4 | choice = raw_input("Sorry, I didn't catch that. Enter again: ") 5 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/String it together/8-Anti_vowels.py: -------------------------------------------------------------------------------- 1 | def anti_vowel(text): 2 | vowels = 'aeiou' 3 | new_text = '' 4 | for i in text: 5 | if i.lower() not in vowels: 6 | new_text += i 7 | print new_text 8 | return new_text 9 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/01 Review/2-Print those grades.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | def print_grades(grades): 4 | c = [] 5 | for i in grades: 6 | c.append(i) 7 | print i 8 | 9 | print_grades(grades) 10 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Iteration Nation/3-The in Operator.py: -------------------------------------------------------------------------------- 1 | my_dict = { "name": "Arthur", "age": 24, "color":"blue", "game":"PoE"} 2 | print my_dict.keys() 3 | print my_dict.values() 4 | 5 | for key in my_dict: 6 | print key, my_dict[key] 7 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/8-Not.py: -------------------------------------------------------------------------------- 1 | bool_one = not True 2 | 3 | bool_two = not 3 ** 4 < 4 ** 3 4 | 5 | bool_three = not 10 % 3 <= 10 % 2 6 | 7 | bool_four = not 3**2 + 4**2 != 5**2 8 | 9 | bool_five = not not False 10 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Function Syntax/4-Parameters and Arguments.py: -------------------------------------------------------------------------------- 1 | def power(base, exponent): # Add your parameters here! 2 | result = base**exponent 3 | print "%d to the power of %d is %d." % (base, exponent, result) 4 | 5 | power(37,4) # Add your arguments here! 6 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Looping and lists/4-Lists + Functions.py: -------------------------------------------------------------------------------- 1 | # Write your function below! 2 | def fizz_count(x): 3 | count = 0 4 | for i in x: 5 | if (i == "fizz"): 6 | count = count + 1 7 | return count 8 | print count 9 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/5-Custom Print.py: -------------------------------------------------------------------------------- 1 | board = [] 2 | 3 | for loop in range(0, 5): 4 | treta = ["O"] * 5 5 | board.append(treta) 6 | 7 | def print_board(board): 8 | for row in board: 9 | print row 10 | 11 | board 12 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/Review/15-Iterating Over Dictionaries.py: -------------------------------------------------------------------------------- 1 | movies = { 2 | "Monty Python and the Holy Grail": "Great", 3 | "Monty Python's Life of Brian": "Good", 4 | "Monty Python's Meaning of Life": "Okay" 5 | } 6 | 7 | print movies.items() 8 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/16-Multiple Lists.py: -------------------------------------------------------------------------------- 1 | list_a = [3, 9, 17, 15, 19] 2 | list_b = [2, 4, 8, 10, 30, 40, 50, 60, 70, 80, 90] 3 | 4 | for a, b in zip(list_a, list_b): 5 | # Add your code here! 6 | if a > b: 7 | print a 8 | else: 9 | print b 10 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/02 Date and Time/3-Extracting Information.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | now = datetime.now() 3 | 4 | current_year = now.year 5 | current_month = now.month 6 | current_day = now.day 7 | 8 | 9 | print now.year 10 | print now.month 11 | print now.day 12 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/6-Printing Pretty.py: -------------------------------------------------------------------------------- 1 | board = [] 2 | 3 | for loop in range(0, 5): 4 | treta = ["O"] * 5 5 | board.append(treta) 6 | 7 | def print_board(board): 8 | for row in board: 9 | print " ".join(row) 10 | 11 | board 12 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/For Loops/12-For your A.py: -------------------------------------------------------------------------------- 1 | phrase = "A bird in the hand..." 2 | 3 | # Add your for loop 4 | for char in phrase: 5 | if char == 'A' or char == 'a': 6 | print 'X', 7 | else: 8 | print char, 9 | 10 | #Don't delete this print statement! 11 | print 12 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/Binary representation/1-Just a Little BIT.py: -------------------------------------------------------------------------------- 1 | print 5 >> 4 # Right Shift 2 | print 5 << 1 # Left Shift 3 | print 8 & 5 # Bitwise AND 4 | print 9 | 4 # Bitwise OR 5 | print 12 ^ 42 # Bitwise XOR 6 | print ~88 # Bitwise NOT 7 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/01 Introduction to file I-O/1-See It to Believe It.py: -------------------------------------------------------------------------------- 1 | my_list = [i**2 for i in range(1,11)] 2 | # Generates a list of squares of the numbers 1 - 10 3 | 4 | f = open("output.txt", "w") 5 | 6 | for item in my_list: 7 | f.write(str(item) + "\n") 8 | 9 | f.close() 10 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/4-Check yourself.py: -------------------------------------------------------------------------------- 1 | print 'Welcome to the Pig Latin Translator!' 2 | 3 | # Start coding here! 4 | original = raw_input('TELL ME a word in ENGRIXH:').lower() 5 | if len(original) >= 0: 6 | print original.lower() 7 | else: 8 | print 'empty' 9 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART2/8-Word up.py: -------------------------------------------------------------------------------- 1 | pyg = 'ay' 2 | 3 | original = raw_input('Enter a word:') 4 | 5 | if len(original) > 0 and original.isalpha(): 6 | word = original.lower() 7 | first = word[0] 8 | print original 9 | else: 10 | print 'empty' 11 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists/2-Access by Index.py: -------------------------------------------------------------------------------- 1 | numbers = [5, 6, 7, 8] 2 | 3 | print "Adding the numbers at indices 0 and 2..." 4 | print numbers[0] + numbers[2] 5 | print "Adding the numbers at indices 1 and 3..." 6 | # Your code here! 7 | print numbers[1] + numbers[3] 8 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using the entire list in a Function/15-Iterating over a list in a function.py: -------------------------------------------------------------------------------- 1 | n = [3, 5, 7] 2 | 3 | def total(numbers): 4 | result = 0 5 | for i in range(len(numbers)): 6 | result += numbers[i] 7 | return result 8 | 9 | print total(n) 10 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/02 The average grade/4-The sum of scores.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | def grades_sum(scores): 4 | total = 0 5 | for n in scores: 6 | total = total + n 7 | print total 8 | return total 9 | grades_sum(grades) 10 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Strings/2-Practice.py: -------------------------------------------------------------------------------- 1 | # Assign your variables below, each on its own line! 2 | caesar = "Graham" 3 | praline = "John" 4 | viking = "Teresa" 5 | 6 | 7 | # Put your variables above this line 8 | 9 | print caesar 10 | print praline 11 | print viking 12 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/6-Pop Quizz.py: -------------------------------------------------------------------------------- 1 | print 'Welcome to the Pig Latin Translator!' 2 | 3 | # Start coding here! 4 | original = raw_input('TELL ME a word in ENGRIXH:').lower() 5 | if len(original) > 0 and original.isalpha(): 6 | print original.lower() 7 | else: 8 | print 'empty' 9 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/01 Advanced Topics in Python/List Comprehentions/5-List Comprehension Syntax.py: -------------------------------------------------------------------------------- 1 | doubles_by_3 = [x*2 for x in range(1,6) if (x*2) % 3 == 0] 2 | 3 | # Complete the following line. Use the line above for help. 4 | even_squares = [x**2 for x in range(2,11) if x%2 == 0] 5 | 6 | print even_squares 7 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/Binary representation/5-int()'s Second Parameter.py: -------------------------------------------------------------------------------- 1 | print int("1",2) 2 | print int("10",2) 3 | print int("111",2) 4 | print int("0b100",2) 5 | print int(bin(5),2) 6 | # Print out the decimal equivalent of the binary 11001001. 7 | print int("0b11001001",2) 8 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/The Bitwise Operators/6-Slide to the Left! Slide to the Right!.py: -------------------------------------------------------------------------------- 1 | shift_right = 0b1100 2 | shift_left = 0b1 3 | 4 | # Your code here! 5 | shift_right = shift_right >> 2 6 | shift_left = shift_left << 2 7 | print bin(shift_right) 8 | print bin(shift_left) 9 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Owning a Store/7-Investing in Stock.py: -------------------------------------------------------------------------------- 1 | prices = { 2 | "banana": 4, 3 | "apple": 2, 4 | "orange": 1.5, 5 | "pear": 3 6 | } 7 | 8 | stock = { 9 | "banana": 6, 10 | "apple": 0, 11 | "orange": 32, 12 | "pear": 15 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/6-Slicing Lists and Strings.py: -------------------------------------------------------------------------------- 1 | animals = "catdogfrog" 2 | cat = animals[:3] # The first three characters of animals 3 | dog = animals[3:6] # The fourth through sixth characters 4 | frog = animals[6:] # From the seventh character to the end 5 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using Lists of Lists in Functions/17-Using two lists as two arguments in a function.py: -------------------------------------------------------------------------------- 1 | m = [1, 2, 3] 2 | n = [4, 5, 6] 3 | n = [3, 5, 7] 4 | # Add your code here! 5 | def join_lists(x, y): 6 | return x + y 7 | print join_lists(m, n) 8 | # You want this to print [1, 2, 3, 4, 5, 6] 9 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/Binary representation/3-I Can Count to 1100!.py: -------------------------------------------------------------------------------- 1 | one = 0b1 2 | two = 0b10 3 | three = 0b11 4 | four = 0b100 5 | five = 0b101 6 | six = 0b110 7 | seven = 0b111 8 | eight = 0b1000 9 | nine = 0b1001 10 | ten = 0b1010 11 | eleven = 0b1011 12 | twelve = 0b1100 13 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART1/5-Check yourself some more.py: -------------------------------------------------------------------------------- 1 | print 'Welcome to the Pig Latin Translator!' 2 | 3 | # Start coding here! 4 | original = raw_input('TELL ME a word in ENGRIXH:').lower() 5 | if len(original) > 0 and original.isalpha(): 6 | print original.lower() 7 | else: 8 | print 'empty' 9 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/String it together/10-censor.py: -------------------------------------------------------------------------------- 1 | def censor(text, word): 2 | words = text.split(" ") 3 | w = [] 4 | for i in words: 5 | if i == word: 6 | w.append(len(i)*"*") 7 | else: 8 | w.append(i) 9 | print " ".join(w) 10 | return " ".join(w) 11 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/If, Else and Elif/12-If youre having.py: -------------------------------------------------------------------------------- 1 | def using_control_once(): 2 | if True: 3 | return "Success #1" 4 | 5 | def using_control_again(): 6 | if True: 7 | return "Success #2" 8 | 9 | print using_control_once() 10 | print using_control_again() 11 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using the entire list in a Function/13-Modifying each element in a list in a function.py: -------------------------------------------------------------------------------- 1 | n = [3, 5, 7] 2 | 3 | def double_list(x): 4 | for i in range(0, len(x)): 5 | x[i] = x[i] * 2 6 | return x 7 | # Don't forget to return your new list! 8 | 9 | print double_list(n) 10 | -------------------------------------------------------------------------------- /Unit 10 Advanced Topics in Python/02 Introduction to Bitwise Operators/Binary representation/2-Lesson I0: The Base 2 Number System.py: -------------------------------------------------------------------------------- 1 | print 0b1, #1 2 | print 0b10, #2 3 | print 0b11, #3 4 | print 0b100, #4 5 | print 0b101, #5 6 | print 0b110, #6 7 | print 0b111 #7 8 | print "******" 9 | print 0b1 + 0b11 10 | print 0b11 * 0b11 11 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using the entire list in a Function/16-Using strings in lists in functions.py: -------------------------------------------------------------------------------- 1 | n = ["Michael", "Lieberman"] 2 | # Add your function here 3 | def join_strings(words): 4 | result = "" 5 | for i in range(len(words)): 6 | result += words[i] 7 | return result 8 | print join_strings(n) 9 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/9-This and That.py: -------------------------------------------------------------------------------- 1 | bool_one = False or not True and True 2 | 3 | bool_two = False and not True or True 4 | 5 | bool_three = True and not (False or False) 6 | 7 | bool_four = not not True or False and not True 8 | 9 | bool_five = False or not (True and True) 10 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART2/9-Move it on back.py: -------------------------------------------------------------------------------- 1 | pyg = 'ay' 2 | 3 | original = raw_input('Enter a word:') 4 | 5 | if len(original) > 0 and original.isalpha(): 6 | word = original.lower() 7 | first = word[0] 8 | 9 | new_word = word + first + pyg 10 | print pyg 11 | else: 12 | print 'empty' 13 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Function Syntax/6-Practice Makes perfect.py: -------------------------------------------------------------------------------- 1 | def cube(number): 2 | raw = number **3 3 | return raw 4 | 5 | def by_three(number): 6 | if number % 3 == 0: 7 | number = number **3 8 | print number 9 | return number 10 | else: 11 | print 'n isnt' 12 | return False 13 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/7-Or.py: -------------------------------------------------------------------------------- 1 | bool_one = 2**3 == 108 % 100 or 'Cleese' == 'King Arthur' 2 | 3 | bool_two = True or False 4 | 5 | bool_three = 100**0.5 >= 50 or False 6 | 7 | bool_four = True or True 8 | 9 | bool_five = 1**100 == 100**1 or 3 * 2 * 1 != 3 + 2 + 1 10 | print bool_five 11 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Function Syntax/3-Call and Response.py: -------------------------------------------------------------------------------- 1 | def square(n): 2 | """Returns the square of a number.""" 3 | squared = n**2 4 | print "%d squared is %d." % (n, squared) 5 | return squared 6 | 7 | # Call the square function on line 9! Make sure to 8 | # include the number 10 between the parentheses. 9 | square(10) 10 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/5-Initializing a class.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = 'new' 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | 9 | my_car = Car("DeLorean", "silver", 88) 10 | print my_car.condition 11 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/17-For, Else.py: -------------------------------------------------------------------------------- 1 | fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape'] 2 | 3 | print 'You have...' 4 | for f in fruits: 5 | if f == 'tomato': 6 | print 'A tomato is not a fruit!' # (It actually is.) 7 | break 8 | print 'A', f 9 | else: 10 | print 'A fine selection of fruits!' 11 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/6-And.py: -------------------------------------------------------------------------------- 1 | bool_one = False and False 2 | print bool_one 3 | 4 | bool_two = -(-(-(-2))) == -2 and 4 >= 16**0.5 5 | 6 | 7 | bool_three = 19 % 4 != 300 / 10 / 10 and False 8 | 9 | 10 | bool_four = -(1**2) < 2**0 and 10 % 10 <= 20 - 10 * 2 11 | 12 | 13 | bool_five = True and True 14 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/Using Classes/11-Building useful classes.py: -------------------------------------------------------------------------------- 1 | class Point3D(object): 2 | def __init__(self, x, y, z): 3 | self.x = x 4 | self.y = y 5 | self.z = z 6 | 7 | def __repr__(self): 8 | return "(%d, %d, %d)" % (self.x, self.y, self.z) 9 | 10 | my_point = Point3D(1,2,3) 11 | print my_point 12 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Advanced Printing/15-String Formatting with, PART 2.py: -------------------------------------------------------------------------------- 1 | name = raw_input("What is your name?") 2 | quest = raw_input("What is your quest?") 3 | color = raw_input("What is your favorite color?") 4 | 5 | print "Ah, so your name is %s, your quest is %s, " \ 6 | "and your favorite color is %s." % (name, quest, color) 7 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Looping and lists/5-String Looping.py: -------------------------------------------------------------------------------- 1 | for letter in "Codecademy": 2 | print letter 3 | 4 | # Empty lines to make the output pretty 5 | print 6 | print 7 | 8 | word = "Programming is fun!" 9 | 10 | for letter in word: 11 | # Only print out the letter i 12 | if letter == "i": 13 | print letter 14 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Looping and lists/2-This is KEY.py: -------------------------------------------------------------------------------- 1 | webster = { 2 | "Aardvark" : "A star of a popular children's cartoon show.", 3 | "Baa" : "The sound a goat makes.", 4 | "Carpet": "Goes on the floor.", 5 | "Dab": "A small amount." 6 | } 7 | 8 | # Add your code below! 9 | for key in webster: 10 | print webster[key] 11 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/18-Change it Up.py: -------------------------------------------------------------------------------- 1 | fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape'] 2 | 3 | print 'You have...' 4 | for f in fruits: 5 | if f == 'tomato': 6 | print 'A tomato is not a fruit!' # (It actually is.) 7 | #REMOVED THE BREAK COMMAND 8 | print 'A', f 9 | else: 10 | print 'A fine selection of fruits!' 11 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/7-Mantaining Order.py: -------------------------------------------------------------------------------- 1 | animals = ["aardvark", "badger", "duck", "emu", "fennec fox"] 2 | duck_index = animals.index('duck') # Use index() to find "duck" 3 | 4 | # Your code here! 5 | animals.insert(duck_index, 'cobra') 6 | 7 | 8 | print animals # Observe what prints after the insert operation 9 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Listing your problems/11-Count.py: -------------------------------------------------------------------------------- 1 | def count (sequence, item): 2 | count = 0 3 | for i in sequence: 4 | if type (item) != list: 5 | if i == item: 6 | count += 1 7 | else: 8 | for n in item: 9 | if n == i: 10 | count += 1 11 | return count 12 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/If, Else and Elif/11-Conditional Statement Syntax.py: -------------------------------------------------------------------------------- 1 | response = 'Y' 2 | 3 | answer = "Left" 4 | if answer == "Left": 5 | print "This is the Verbal Abuse Room, you heap of parrot droppings!" 6 | 7 | # Will the above print statement print to the console? 8 | # Set response to 'Y' if you think so, and 'N' if you think not. 9 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Dictionaries/10-This next part is key.py: -------------------------------------------------------------------------------- 1 | # Assigning a dictionary with three key-value pairs to residents: 2 | residents = {'Puffin' : 104, 'Sloth' : 105, 'Burmese Python' : 106} 3 | 4 | print residents['Puffin'] # Prints Puffin's room number 5 | 6 | # Your code here! 7 | print residents['Sloth'] 8 | print residents['Burmese Python'] 9 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART2/10-Engind up.py: -------------------------------------------------------------------------------- 1 | pyg = 'ay' 2 | 3 | original = raw_input('Enter a word:') 4 | 5 | if len(original) > 0 and original.isalpha(): 6 | word = original.lower() 7 | first = word[0] 8 | 9 | new_word = word + first + pyg 10 | new_word = new_word[1:len(new_word)] 11 | print new_word 12 | else: 13 | print 'empty' 14 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/List Recap/4-Removing elements from lists.py: -------------------------------------------------------------------------------- 1 | n = [1, 3, 5] 2 | # Removes 1 from the list, 3 | # NOT the item at index 1 4 | n.remove(1) 5 | # Another possible solution, will remove the item at the given index: 6 | del(n[0]) 7 | # Another possible solution will remove the item at index from the list and return it to you: 8 | n.pop(0) 9 | print n 10 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/If, Else and Elif/14-I got 99 problems but a switch aint one.py: -------------------------------------------------------------------------------- 1 | def greater_less_equal_5(answer): 2 | if answer > 5: 3 | return 1 4 | elif answer <5: 5 | return -1 6 | else: 7 | return 0 8 | 9 | print greater_less_equal_5(4) 10 | print greater_less_equal_5(5) 11 | print greater_less_equal_5(6) 12 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/01 Lists and Functions/Using Lists of Lists in Functions/18-Using a list of lists in a function.py: -------------------------------------------------------------------------------- 1 | n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]] 2 | # Add your function here 3 | def flatten(lists): 4 | results = [] 5 | for i in range(len(lists)): 6 | for j in range(len(lists[i])): 7 | results.append(lists[i][j]) 8 | return results 9 | print flatten(n) 10 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/A review of Classes/6-Referring to member variables.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | my_car = Car("Chevv","GOLDEN", 1933) 9 | 10 | print my_car.model 11 | print my_car.color 12 | print my_car.mpg 13 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/02 PygLatin/PygLatin PART2/11-Testing is this thing on.py: -------------------------------------------------------------------------------- 1 | pyg = 'ay' 2 | 3 | original = raw_input('Enter a word:') 4 | 5 | if len(original) > 0 and original.isalpha(): 6 | word = original.lower() 7 | first = word[0] 8 | 9 | new_word = word + first + pyg 10 | new_word = new_word[1:len(new_word)] 11 | print new_word 12 | else: 13 | print 'empty' 14 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Member Variables and Functions/8-A Methodical Approach.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | """Makes cute animals.""" 3 | is_alive = True 4 | def __init__(self, name, age): 5 | self.name = name 6 | self.age = age 7 | # Add your method here! 8 | def description(self): 9 | print self.name 10 | print self.age 11 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/7-While and Else.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print "Lucky Numbers! 3 numbers will be generated." 4 | print "If one of them is a '5', you lose!" 5 | 6 | count = 0 7 | while count < 3: 8 | num = random.randint(1, 6) 9 | print num 10 | if num == 5: 11 | print "Sorry, you lose!" 12 | break 13 | count += 1 14 | else: 15 | print "You win!" 16 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/6-is_prime.py: -------------------------------------------------------------------------------- 1 | def is_prime(x): 2 | Prime = False 3 | if (x < 2): 4 | Prime = False 5 | elif (x == 2): 6 | Prime = True 7 | else: 8 | for n in range(2,x): 9 | if ( x % n) == 0: 10 | Prime = False 11 | break 12 | else: 13 | Prime = True 14 | return Prime 15 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/01 Good Morning Class/1-Lesson number one.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | 'name':'Lloyd', 3 | 'homework':[], 4 | 'quizzes':[], 5 | 'tests':[] 6 | } 7 | 8 | alice = { 9 | 'name':'Alice', 10 | 'homework':[], 11 | 'quizzes':[], 12 | 'tests':[] 13 | } 14 | 15 | tyler = { 16 | 'name':'Tyler', 17 | 'homework':[], 18 | 'quizzes':[], 19 | 'tests':[] 20 | } 21 | -------------------------------------------------------------------------------- /Unit 01 Python Syntax/01 Python Syntax/Varibles and Data Types/Youve-been-reassigned.py: -------------------------------------------------------------------------------- 1 | # my_int is set to 7 below. What do you think 2 | # will happen if we reset it to 3 and print the result? 3 | 4 | my_int = 7 5 | 6 | # Change the value of my_int to 3 on line 8! 7 | 8 | my_int = 3 9 | 10 | # Here's some code that will print my_int to the console: 11 | # The print keyword will be covered in detail soon! 12 | 13 | print my_int 14 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Built In Functions/12-On beyond Strings.py: -------------------------------------------------------------------------------- 1 | def biggest_number(*args): 2 | print max(args) 3 | return max(args) 4 | 5 | def smallest_number(*args): 6 | print min(args) 7 | return min(args) 8 | 9 | def distance_from_zero(arg): 10 | print abs(arg) 11 | return abs(arg) 12 | 13 | 14 | biggest_number(-10, -5, 5, 10) 15 | smallest_number(-10, -5, 5, 10) 16 | distance_from_zero(-10) 17 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/5-List Slicing.py: -------------------------------------------------------------------------------- 1 | suitcase = ["sunglasses", "hat", "passport", "laptop", "suit", "shoes"] 2 | 3 | first = suitcase[0:2] # The first and second items (index zero and one) 4 | print first 5 | middle = suitcase[2:4] # Third and fourth items (index two and three) 6 | print middle 7 | last = suitcase[4:6] # The last two items (index four and five) 8 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/9-More with for.py: -------------------------------------------------------------------------------- 1 | start_list = [5, 3, 1, 2, 4] 2 | square_list = [] 3 | 4 | # for loop number is ambiguous variable 5 | 6 | for number in start_list: 7 | square = number ** 2 # calculate square to add later 8 | square_list.append(square) # add the calculation 9 | square_list.sort() 10 | print square_list # print sorted version 11 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Dictionaries/11-New Entries.py: -------------------------------------------------------------------------------- 1 | menu = {} # Empty dictionary 2 | menu['Chicken Alfredo'] = 14.50 # Adding new key-value pair 3 | print menu['Chicken Alfredo'] 4 | 5 | # Your code here: Add some dish-price pairs to menu! 6 | menu['treta'] = 2.3 7 | menu['treta2'] = 24.3 8 | menu['treta3'] = 22.3 9 | 10 | 11 | print "There are " + str(len(menu)) + " items on the menu." 12 | print menu 13 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/02 The Devil's in the Details/6-PSA: Buffering Data.py: -------------------------------------------------------------------------------- 1 | # Open the file for reading 2 | read_file = open("text.txt", "r") 3 | 4 | # Use a second file handler to open the file for writing 5 | write_file = open("text.txt", "w") 6 | # Write to the file 7 | write_file.write("Not closing files is VERY BAD.") 8 | 9 | # Try to read from the file 10 | print read_file.read() 11 | write_file.close() 12 | read_file.close() 13 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists Capabilities and Functions/4-Late Arrivals and List length.py: -------------------------------------------------------------------------------- 1 | suitcase = [] 2 | suitcase.append("sunglasses") 3 | 4 | # Your code here! 5 | suitcase.append('treta') 6 | suitcase.append('azul') 7 | suitcase.append('cell') 8 | 9 | list_length = len(suitcase) # Set this to the length of suitcase 10 | 11 | print "There are %d items in the suitcase." % (list_length) 12 | print suitcase 13 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists/3-New Neibors.py: -------------------------------------------------------------------------------- 1 | zoo_animals = ["pangolin", "cassowary", "sloth", "tiger"] 2 | # Last night our zoo's sloth brutally attacked 3 | #the poor tiger and ate it whole. 4 | 5 | # The ferocious sloth has been replaced by a friendly hyena. 6 | zoo_animals[2] = "hyena" 7 | 8 | # What shall fill the void left by our dear departed tiger? 9 | # Your code here! 10 | zoo_animals[3] = 'teta' 11 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Owning a Store/8-Keeping track of the Produce.py: -------------------------------------------------------------------------------- 1 | prices = { 2 | "banana": 4, 3 | "apple": 2, 4 | "orange": 1.5, 5 | "pear": 3 6 | } 7 | 8 | stock = { 9 | "banana": 6, 10 | "apple": 0, 11 | "orange": 32, 12 | "pear": 15 13 | } 14 | 15 | for key in prices: 16 | print "%s" %key 17 | print "price: %s" %prices[key] 18 | print "stock: %s" %stock[key] 19 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/5-To be or not To be.py: -------------------------------------------------------------------------------- 1 | """ 2 | Boolean Operators 3 | ------------------------ True and True is True 4 | True and False is False 5 | False and True is False 6 | False and False is False 7 | 8 | True or True is True 9 | True or False is True 10 | False or True is True 11 | False or False is False 12 | 13 | Not True is False 14 | Not False is True 15 | 16 | """ 17 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Comparators/4-How the talbes have Turned.py: -------------------------------------------------------------------------------- 1 | # Create comparative statements as appropriate on the lines below! 2 | 3 | # Make me true! 4 | bool_one = 3 < 5 # We already did this one for you! 5 | 6 | # Make me false! 7 | bool_two = 3>= 6 8 | 9 | # Make me true! 10 | bool_three = 2!= 3 11 | 12 | # Make me false! 13 | bool_four = 43 <=40 14 | 15 | # Make me true! 16 | bool_five = 90> 2 17 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Review/16-Class It Up.py: -------------------------------------------------------------------------------- 1 | class Triangle(object): 2 | def __init__(self, angle1, angle2, angle3): 3 | self.angle1 = angle1 4 | self.angle2 = angle2 5 | self.angle3 = angle3 6 | 7 | number_of_sides = 3 8 | def check_angles(self): 9 | if (self.angle1+self.angle2+self.angle3) == 180: 10 | return True 11 | else: 12 | return False 13 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Function Syntax/2- Function Junction.py: -------------------------------------------------------------------------------- 1 | def tax(bill): 2 | """Adds 8% tax to a restaurant bill.""" 3 | bill *= 1.08 4 | print "With tax: %f" % bill 5 | return bill 6 | 7 | def tip(bill): 8 | """Adds 15% tip to a restaurant bill.""" 9 | bill *= 1.15 10 | print "With tip: %f" % bill 11 | return bill 12 | 13 | meal_cost = 100 14 | meal_with_tax = tax(meal_cost) 15 | meal_with_tip = tip(meal_with_tax) 16 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/3-Getting there.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | 5 | def plane_ride_cost(city): 6 | if city == 'Charlotte': 7 | return 183 8 | elif city == 'Tampa': 9 | return 220 10 | elif city == 'Pittsburgh': 11 | return 222 12 | elif city == 'Los Angeles': 13 | return 475 14 | print plane_ride_cost('Charlotte') 15 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Lists/1-Introduction to Lists.py: -------------------------------------------------------------------------------- 1 | zoo_animals = ["pangolin", "cassowary", "sloth", ]; 2 | # One animal is missing! 3 | 4 | if len(zoo_animals) > 3: 5 | print "The first animal at the zoo is the " + zoo_animals[0] 6 | print "The second animal at the zoo is the " + zoo_animals[1] 7 | print "The third animal at the zoo is the " + zoo_animals[2] 8 | print "The fourth animal at the zoo is the " + zoo_animals[3] 9 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/Fun with Numbers/6-is_prime using for loop.py: -------------------------------------------------------------------------------- 1 | def is_prime(x): 2 | n = 2 3 | Prime = False 4 | if x <2: 5 | Prime = False 6 | else: 7 | while n < x: 8 | if x % n == 0: 9 | Prime = False 10 | break 11 | else: 12 | n +=1 13 | Prime = True 14 | else: 15 | Prime = True 16 | return Prime 17 | -------------------------------------------------------------------------------- /Unit 02 Strings and Console Output/01 Strings and Console Outputs/Strings/4-Access by Index.py: -------------------------------------------------------------------------------- 1 | """ 2 | The string "PYTHON" has six characters, 3 | numbered 0 to 5, as shown below: 4 | 5 | +---+---+---+---+---+---+ 6 | | P | Y | T | H | O | N | 7 | +---+---+---+---+---+---+ 8 | 0 1 2 3 4 5 9 | 10 | So if you wanted "Y", you could just type 11 | "PYTHON"[1] (always start counting from 0!) 12 | """ 13 | fifth_letter = "MONTY"[4] 14 | 15 | print fifth_letter 16 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/Using Classes/7-Creating class methods.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | def display_car(self): 9 | return "This is a %s %s with %s MPG." % (self.color, self.model, self.mpg) 10 | 11 | my_car = Car("DeLorean","silver", 88) 12 | print my_car.display_car() 13 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Inheritance/12-Inheritance Syntax.py: -------------------------------------------------------------------------------- 1 | class Shape(object): 2 | """Makes shapes!""" 3 | 4 | def __init__(self, number_of_sides): 5 | self.number_of_sides = number_of_sides 6 | 7 | # Add your Triangle class below! 8 | 9 | 10 | class Triangle(Shape): 11 | 12 | def __init__(self, side1, side2, side3): 13 | self.side1 = side1 14 | self.side2 = side2 15 | self.side3 = side3 16 | -------------------------------------------------------------------------------- /Unit 04 Functions/01 Functions/Introduction to Functions/1-What good are functions.py: -------------------------------------------------------------------------------- 1 | def tax(bill): 2 | """Adds 8% tax to a restaurant bill.""" 3 | bill *= 1.08 4 | print "With tax: %f" % bill 5 | return bill 6 | 7 | def tip(bill): 8 | """Adds 15% tip to a restaurant bill.""" 9 | bill *= 1.15 10 | print "With tip: %f" % bill 11 | return bill 12 | 13 | meal_cost = 100 14 | meal_with_tax = tax(meal_cost) 15 | meal_with_tip = tip(meal_with_tax) 16 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/02 The average grade/5-Computing the Average.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | 4 | def grades_sum(scores): 5 | total = 0 6 | for n in scores: 7 | total = total + n 8 | print total 9 | return total 10 | 11 | 12 | def grades_average(grades): 13 | grades_sum(grades) 14 | avrg = grades_sum(grades) / float(len(grades)) 15 | print avrg 16 | return avrg 17 | 18 | grades_average(grades) 19 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Review/15-The big If.py: -------------------------------------------------------------------------------- 1 | # Make sure that the_flying_circus() returns True 2 | def the_flying_circus(): 3 | if 10 < 11 or 5<(6+1): # Start coding here! 4 | return True # Don't forget to indent 5 | # the code inside this block! 6 | elif 7 >= 2: 7 | return False # Keep going here. 8 | # You'll want to add the else statement, too! 9 | else: 10 | return True 11 | 12 | print the_flying_circus() 13 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/7-Hide.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0, 5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | # Add your code below! 13 | def random_row(board): 14 | return randint(0, len(board) - 1) 15 | 16 | def random_col(board): 17 | return randint(0, len(board[0]) - 1) 18 | 19 | print random_row(board) 20 | print random_col(board) 21 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Shopping Trip/11-Making a purchase.py: -------------------------------------------------------------------------------- 1 | shopping_list = ["banana", "orange", "apple"] 2 | 3 | stock = { 4 | "banana": 6, 5 | "apple": 0, 6 | "orange": 32, 7 | "pear": 15 8 | } 9 | 10 | prices = { 11 | "banana": 4, 12 | "apple": 2, 13 | "orange": 1.5, 14 | "pear": 3 15 | } 16 | 17 | # Write your code below! 18 | def compute_bill(food): 19 | total = 0 20 | for n in food: 21 | total = total + prices[n] 22 | return total 23 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Inheritance/13-Override.py: -------------------------------------------------------------------------------- 1 | class Employee(object): 2 | """Models real-life employees!""" 3 | def __init__(self, employee_name): 4 | self.employee_name = employee_name 5 | 6 | def calculate_wage(self, hours): 7 | self.hours = hours 8 | return hours * 20.00 9 | 10 | # Add your code below! 11 | class PartTimeEmployee(Employee): 12 | 13 | def calculate_wage(self, hours): 14 | self.hours = hours 15 | return hours*12 16 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/If, Else and Elif/13-else problems, I feel bad for you son.py: -------------------------------------------------------------------------------- 1 | answer = "'Tis but a scratch!" 2 | 3 | def black_knight(): 4 | if answer == "'Tis but a scratch!": 5 | return True 6 | else: 7 | return False # Make sure this returns False 8 | 9 | def french_soldier(): 10 | if answer == "Go away, or I shall taunt you a second time!": 11 | return True 12 | else: 13 | return False # Make sure this returns False 14 | -------------------------------------------------------------------------------- /Unit 08 Loops/02 Practice makes perfect/String it together/9-scrabble_score.py: -------------------------------------------------------------------------------- 1 | score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2, 2 | "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3, 3 | "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1, 4 | "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4, 5 | "x": 8, "z": 10} 6 | 7 | 8 | def scrabble_score(word): 9 | word = word.lower() 10 | total = 0 11 | for i in word: 12 | total = total + (score[i]) 13 | print total 14 | return total 15 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Member Variables and Functions/7-Class Scope.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | """Makes cute animals.""" 3 | is_alive = True 4 | def __init__(self, name, age): 5 | self.name = name 6 | self.age = age 7 | 8 | zebra = Animal("Jeffrey", 2) 9 | giraffe = Animal("Bruce", 1) 10 | panda = Animal("Chad", 7) 11 | 12 | print zebra.name, zebra.age, zebra.is_alive 13 | print giraffe.name, giraffe.age, giraffe.is_alive 14 | print panda.name, panda.age, panda.is_alive 15 | -------------------------------------------------------------------------------- /Unit 08 Loops/01 Loops/Step Up 'For's/While Loops/8-Your own While and Else.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | # Generates a number from 1 through 10 inclusive 4 | random_number = randint(1, 10) 5 | 6 | guesses_left = 3 7 | # Start your game! 8 | 9 | while guesses_left > 0: 10 | print 'You got %s guesses left' % guesses_left 11 | guess = int(raw_input('Guess a number (1-10):')) 12 | 13 | if guess == random_number: 14 | print 'You win!' 15 | break 16 | guesses_left -= 1 17 | else: 18 | print 'You lose.' 19 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Boolean Operators/10-Min 'n' match.py: -------------------------------------------------------------------------------- 1 | # Use boolean expressions as appropriate on the lines below! 2 | 3 | # Make me false! 4 | bool_one = (2 <= 2) and "Alpha" == "Bravo" # We did this one for you! 5 | 6 | # Make me true! 7 | bool_two = (3 >= 1) or "Daniel" == "Dariana" 8 | 9 | # Make me false! 10 | bool_three = (234<= 33) and (True and False) 11 | 12 | # Make me true! 13 | bool_four = (32 > 23) and 'arthur' == 'arthur' 14 | 15 | # Make me true! 16 | bool_five = (54 != 33) or True 17 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/01 Good Morning Class/2-Whats the score.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Owning a Store/9-Something of value.py: -------------------------------------------------------------------------------- 1 | prices = { 2 | "banana" : 4, 3 | "apple" : 2, 4 | "orange" : 1.5, 5 | "pear" : 3, 6 | } 7 | stock = { 8 | "banana" : 6, 9 | "apple" : 0, 10 | "orange" : 32, 11 | "pear" : 15, 12 | } 13 | 14 | for key in prices: 15 | print key 16 | print "price: %s" % prices[key] 17 | print "stock: %s" % stock[key] 18 | 19 | total = 0 20 | 21 | 22 | for n in stock: 23 | total = total + (stock[n] * prices[n]) 24 | 25 | print total 26 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Review/17-Instantiate an Object.py: -------------------------------------------------------------------------------- 1 | class Triangle(object): 2 | def __init__(self, angle1, angle2, angle3): 3 | self.angle1 = angle1 4 | self.angle2 = angle2 5 | self.angle3 = angle3 6 | 7 | number_of_sides = 3 8 | def check_angles(self): 9 | if (self.angle1+self.angle2+self.angle3) == 180: 10 | return True 11 | else: 12 | return False 13 | my_triangle = Triangle(90, 30, 60) 14 | print my_triangle.number_of_sides 15 | print my_triangle.check_angles() 16 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/01 Good Morning Class/3-Put it together.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | students = [lloyd, alice, tyler] 21 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/Using Classes/8-Modifying member variables.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | def display_car(self): 9 | return "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg)) 10 | 11 | def drive_car(self): 12 | self.condition = "used" 13 | return self.condition 14 | 15 | my_car = Car("DeLorean","silver", 88) 16 | print (my_car.condition) 17 | print my_car.drive_car() 18 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Member Variables and Functions/9-They are Multiplying.py: -------------------------------------------------------------------------------- 1 | class Animal(object): 2 | """Makes cute animals.""" 3 | is_alive = True 4 | health = "good" 5 | def __init__(self, name, age): 6 | self.name = name 7 | self.age = age 8 | # Add your method here! 9 | def description(self): 10 | print self.name 11 | print self.age 12 | 13 | hippo = Animal("HipoCrita",3) 14 | sloth = Animal("Jofrado", 30) 15 | ocelot = Animal("BR_HU3", 666) 16 | 17 | print hippo.health 18 | print sloth.health 19 | print ocelot.health 20 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Comparators/3-Compare Closier.py: -------------------------------------------------------------------------------- 1 | # Assign True or False as appropriate on the lines below! 2 | 3 | # (20 - 10) > 15 4 | bool_one = False # We did this one for you! 5 | 6 | # (10 + 17) == 3**16 7 | # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million. 8 | bool_two = (10+17)>3**16 9 | print str(bool_two) 10 | 11 | # 1**2 <= -1 12 | bool_three = 1**2 <= -1 13 | print str(bool_three) 14 | 15 | # 40 * 4 >= -4 16 | bool_four = 40*4 >=-4 17 | print str(bool_four) 18 | 19 | # 100 != 10**2 20 | bool_five = 100 != 10**2 21 | print bool_five 22 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/8-And Seek.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0,5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | def random_row(board): 13 | return randint(0, len(board) - 1) 14 | 15 | def random_col(board): 16 | return randint(0, len(board[0]) - 1) 17 | 18 | ship_row = random_row(board) 19 | ship_col = random_col(board) 20 | 21 | # Add your code below! 22 | guess_row = int(raw_input('Guess Row: ')) 23 | guess_col = int(raw_input('Guess Col: ')) 24 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Shopping Trip/12-Stocking Out.py: -------------------------------------------------------------------------------- 1 | shopping_list = ["banana", "orange", "apple"] 2 | 3 | stock = { 4 | "banana": 6, 5 | "apple": 0, 6 | "orange": 32, 7 | "pear": 15 8 | } 9 | 10 | prices = { 11 | "banana": 4, 12 | "apple": 2, 13 | "orange": 1.5, 14 | "pear": 3 15 | } 16 | 17 | # Write your code below! 18 | def compute_bill(food): 19 | total = 0 20 | for n in food: 21 | if stock[n] > 0: 22 | total = total + prices[n] 23 | stock[n] -= 1 24 | else: 25 | total = total 26 | print total 27 | return total 28 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/02 A Day at the Supermarket/Shopping Trip/13-Lets Check out.py: -------------------------------------------------------------------------------- 1 | shopping_list = ["banana", "orange", "apple"] 2 | 3 | stock = { 4 | "banana": 6, 5 | "apple": 0, 6 | "orange": 32, 7 | "pear": 15 8 | } 9 | 10 | prices = { 11 | "banana": 4, 12 | "apple": 2, 13 | "orange": 1.5, 14 | "pear": 3 15 | } 16 | 17 | # Write your code below! 18 | def compute_bill(food): 19 | total = 0 20 | for n in food: 21 | if stock[n] > 0: 22 | total = total + prices[n] 23 | stock[n] -= 1 24 | else: 25 | total = total 26 | print total 27 | return total 28 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Introduction to Control Flow/1-Go with the Flow.py: -------------------------------------------------------------------------------- 1 | def clinic(): 2 | print "You've just entered the clinic!" 3 | print "Do you take the door on the left or the right?" 4 | answer = raw_input("Type left or right and hit 'Enter'.").lower() 5 | if answer == "left" or answer == "l": 6 | print "This is the Verbal Abuse Room, you heap of parrot droppings!" 7 | elif answer == "right" or answer == "r": 8 | print "Of course this is the Argument Room, I've told you that already!" 9 | else: 10 | print "You didn't pick left or right! Try again." 11 | clinic() 12 | 13 | clinic() 14 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Dictionaries/12-Changing your mind.py: -------------------------------------------------------------------------------- 1 | # key - animal_name : value - location 2 | zoo_animals = { 'Unicorn' : 'Cotton Candy House', 3 | 'Sloth' : 'Rainforest Exhibit', 4 | 'Bengal Tiger' : 'Jungle House', 5 | 'Atlantic Puffin' : 'Arctic Exhibit', 6 | 'Rockhopper Penguin' : 'Arctic Exhibit'} 7 | # A dictionary (or list) declaration may break across multiple lines 8 | 9 | # Removing the 'Unicorn' entry. (Unicorns are incredibly expensive.) 10 | del zoo_animals['Unicorn'] 11 | 12 | # Your code here! 13 | del zoo_animals['Sloth'] 14 | del zoo_animals['Bengal Tiger'] 15 | zoo_animals['Rockhopper Penguin'] = 2 16 | 17 | print zoo_animals 18 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Dont Sinc my Battleship/9-It's Not Cheating—It's Debugging.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0,5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | def random_row(board): 13 | return randint(0, len(board) - 1) 14 | 15 | def random_col(board): 16 | return randint(0, len(board[0]) - 1) 17 | 18 | ship_row = random_row(board) 19 | ship_col = random_col(board) 20 | 21 | # Add your code below! 22 | guess_row = int(raw_input('Guess Row: ')) 23 | guess_col = int(raw_input('Guess Col: ')) 24 | print ship_col 25 | print ship_row 26 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/01 Good Morning Class/4-For the Record.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | students = [lloyd, alice, tyler] 21 | 22 | for student in students: 23 | for item in student: 24 | print student[item] 25 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/03 Do the grades vary?/7-The Variance.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | def print_grades(grades): 4 | for grade in grades: 5 | print grade 6 | 7 | def grades_sum(grades): 8 | total = 0 9 | for grade in grades: 10 | total += grade 11 | return total 12 | 13 | def grades_average(grades): 14 | sum_of_grades = grades_sum(grades) 15 | average = sum_of_grades / float(len(grades)) 16 | return average 17 | 18 | def grades_variance(grades): 19 | variance = 0 20 | for g in grades: 21 | variance += ((grades_average(grades) - g) ** 2) 22 | return variance / len(grades) 23 | print grades_variance(grades) 24 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Inheritance/11-Warning: Here Be Dragons.py: -------------------------------------------------------------------------------- 1 | class Customer(object): 2 | """Produces objects that represent customers.""" 3 | def __init__(self, customer_id): 4 | self.customer_id = customer_id 5 | 6 | def display_cart(self): 7 | print "I'm a string that stands in for the contents of your shopping cart!" 8 | 9 | class ReturningCustomer(Customer): 10 | """For customers of the repeat variety.""" 11 | def display_order_history(self): 12 | print "I'm a string that stands in for your order history!" 13 | 14 | monty_python = ReturningCustomer("ID: 12345") 15 | monty_python.display_cart() 16 | monty_python.display_order_history() 17 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/4-Transportation.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | 5 | def plane_ride_cost(city): 6 | if city == 'Charlotte': 7 | return 183 8 | elif city == 'Tampa': 9 | return 220 10 | elif city == 'Pittsburgh': 11 | return 222 12 | elif city == 'Los Angeles': 13 | return 475 14 | 15 | def rental_car_cost(days): 16 | total = days*40 17 | if days >= 7: 18 | tuto = total - 50 19 | return tuto 20 | elif days >= 3 and days < 7: 21 | tato = total - 20 22 | return tato 23 | else: 24 | total = days*40 25 | return total 26 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/02 Just Average/5-Its okay to be average.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | # Add your function below! 21 | def average(numbers): 22 | total = sum(numbers) 23 | total = float(total) / float(len(numbers)) 24 | return total 25 | -------------------------------------------------------------------------------- /Unit 12 File Input and Output/02 The Devil's in the Details/5-Reading Between the Lines.py: -------------------------------------------------------------------------------- 1 | my_file = open("text.txt", "r") 2 | print my_file.readline() 3 | print my_file.readline() 4 | print my_file.readline() 5 | my_file.close() 6 | 7 | """ Sometimes only this code can get an 8 | error message, so to skip this problem 9 | you can use this code below """ 10 | 11 | my_file = open("text.txt", "w") 12 | my_file.write("I'm the first line of the file!" + "\n") 13 | my_file.write("I'm the second line." + "\n") 14 | my_file.write("Third line here, boss." + "\n") 15 | my_file.close() 16 | 17 | my_file = open("text.txt", "r") 18 | print my_file.readline() 19 | print my_file.readline() 20 | print my_file.readline() 21 | my_file.close() 22 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Inheritance/14-This Looks Like a Job For.py: -------------------------------------------------------------------------------- 1 | class Employee(object): 2 | """Models real-life employees!""" 3 | def __init__(self, employee_name): 4 | self.employee_name = employee_name 5 | 6 | def calculate_wage(self, hours): 7 | self.hours = hours 8 | return hours * 20.00 9 | 10 | # Add your code below! 11 | class PartTimeEmployee(Employee): 12 | 13 | def calculate_wage(self, hours): 14 | self.hours = hours 15 | return hours*12 16 | 17 | def full_time_wage(self, hours): 18 | return super(PartTimeEmployee, self).calculate_wage(hours) 19 | 20 | milton = PartTimeEmployee("Santos") 21 | print milton.full_time_wage(10) 22 | -------------------------------------------------------------------------------- /Unit 03 Conditionals and Control Flow/01 Conditionals & Control Flow/Comparators/2-Compare Closely.py: -------------------------------------------------------------------------------- 1 | # Assign True or False as appropriate on the lines below! 2 | 3 | # Set this to True if 17 < 328 or to False if it is not. 4 | bool_one = True # We did this one for you! 5 | 6 | # Set this to True if 100 == (2 * 50) or to False otherwise 7 | 8 | bool_two = 100 == (2*50) 9 | print str(bool_two) 10 | 11 | # Set this to True if 19 <= 19 or to False if it is not. 12 | bool_three = 19 <= 19 13 | print str(bool_three) 14 | 15 | # Set this to True if -22 >= -18 or to False if it is not. 16 | bool_four = -22 >= -18 17 | print str(bool_four) 18 | 19 | # Set this to True if 99 != (98 + 1) or to False otherwise. 20 | bool_five = 99 != (98+1) 21 | print str(bool_five) 22 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Review/18-Inheritance.py: -------------------------------------------------------------------------------- 1 | class Triangle(object): 2 | def __init__(self, angle1, angle2, angle3): 3 | self.angle1 = angle1 4 | self.angle2 = angle2 5 | self.angle3 = angle3 6 | 7 | number_of_sides = 3 8 | def check_angles(self): 9 | if (self.angle1+self.angle2+self.angle3) == 180: 10 | return True 11 | else: 12 | return False 13 | my_triangle = Triangle(90, 30, 60) 14 | print my_triangle.number_of_sides 15 | print my_triangle.check_angles() 16 | 17 | class Equilateral(Triangle): 18 | angle = 60 19 | def __init__(self): 20 | self.angle1 = self.angle 21 | self.angle2 = self.angle 22 | self.angle3 = self.angle 23 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Class Basics/1-Why Use Classes.py: -------------------------------------------------------------------------------- 1 | class Fruit(object): 2 | """A class that makes various tasty fruits.""" 3 | def __init__(self, name, color, flavor, poisonous): 4 | self.name = name 5 | self.color = color 6 | self.flavor = flavor 7 | self.poisonous = poisonous 8 | 9 | def description(self): 10 | print "I'm a %s %s and I taste %s." % (self.color, self.name, self.flavor) 11 | 12 | def is_edible(self): 13 | if not self.poisonous: 14 | print "Yep! I'm edible." 15 | else: 16 | print "Don't eat me! I am super poisonous." 17 | 18 | lemon = Fruit("lemon", "yellow", "sour", False) 19 | 20 | lemon.description() 21 | lemon.is_edible() 22 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Hit or Miss/10-You Win.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0, 5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print_board(board) 13 | 14 | def random_row(board): 15 | return randint(0, len(board) - 1) 16 | 17 | def random_col(board): 18 | return randint(0, len(board[0]) - 1) 19 | 20 | ship_row = random_row(board) 21 | ship_col = random_col(board) 22 | guess_row = int(raw_input("Guess Row:")) 23 | guess_col = int(raw_input("Guess Col:")) 24 | 25 | print ship_row 26 | print ship_col 27 | 28 | # Write your code below! 29 | if guess_row == ship_row and guess_col == ship_col: 30 | print "Congratulations! You sank my battleship!" 31 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Member Variables and Functions/6-More on init and self.py: -------------------------------------------------------------------------------- 1 | # Class definition 2 | class Animal(object): 3 | """Makes cute animals.""" 4 | # For initializing our instance objects 5 | def __init__(self, name, age, is_hungry): 6 | self.name = name 7 | self.age = age 8 | self.is_hungry = is_hungry 9 | 10 | # Note that self is only used in the __init__() 11 | # function definition; we don't need to pass it 12 | # to our instance objects. 13 | 14 | zebra = Animal("Jeffrey", 2, True) 15 | giraffe = Animal("Bruce", 1, False) 16 | panda = Animal("Chad", 7, True) 17 | 18 | print zebra.name, zebra.age, zebra.is_hungry 19 | print giraffe.name, giraffe.age, giraffe.is_hungry 20 | print panda.name, panda.age, panda.is_hungry 21 | -------------------------------------------------------------------------------- /Unit 05 Lists & Dictionaries/01 Python Lists and Dictionaries/Dictionaries/14-Its dangerous to go alone!Take this.py: -------------------------------------------------------------------------------- 1 | inventory = { 2 | 'gold' : 500, 3 | 'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key 4 | 'backpack' : ['xylophone','dagger', 'bedroll','bread loaf'] 5 | } 6 | 7 | # Adding a key 'burlap bag' and assigning a list to it 8 | inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth'] 9 | 10 | # Sorting the list found under the key 'pouch' 11 | inventory['pouch'].sort() 12 | 13 | # Your code here 14 | inventory['pocket'] = ['seashell', 'strange berry', 'lint'] 15 | inventory['pocket'].sort() 16 | inventory['backpack'].sort() 17 | inventory['backpack'].remove('dagger') 18 | inventory['backpack'].sort() 19 | inventory['gold'] = inventory['gold'] +50 20 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/5-Pull it together.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | 5 | def plane_ride_cost(city): 6 | if city == 'Charlotte': 7 | return 183 8 | elif city == 'Tampa': 9 | return 220 10 | elif city == 'Pittsburgh': 11 | return 222 12 | elif city == 'Los Angeles': 13 | return 475 14 | 15 | def rental_car_cost(days): 16 | total = days*40 17 | if days >= 7: 18 | tuto = total - 50 19 | return tuto 20 | elif days >= 3 and days < 7: 21 | tato = total - 20 22 | return tato 23 | else: 24 | total = days*40 25 | return total 26 | 27 | def trip_cost(city, days): 28 | notreal = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) 29 | return notreal 30 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/examstats.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | def print_grades(grades): 4 | for value in grades: 5 | print value 6 | print_grades(grades) 7 | 8 | def grades_sum(scores): 9 | sum=0 10 | for i in scores: 11 | sum+=i 12 | return sum 13 | print grades_sum(grades) 14 | 15 | def grades_average(grades): 16 | average=grades_sum(grades)/float(len(grades)) 17 | return average 18 | print grades_average(grades) 19 | 20 | def grades_variance(scores): 21 | average=grades_average(scores) 22 | variance=0 23 | for score in scores: 24 | variance+=(average-score)**2 25 | return variance/len(scores) 26 | print grades_variance(grades) 27 | 28 | def grades_std_deviation(variance): 29 | return variance**0.5 30 | 31 | variance=grades_variance(grades) 32 | print variance 33 | print grades_std_deviation(variance) 34 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/6-Hey, You never know.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | 5 | def plane_ride_cost(city): 6 | if city == 'Charlotte': 7 | return 183 8 | elif city == 'Tampa': 9 | return 220 10 | elif city == 'Pittsburgh': 11 | return 222 12 | elif city == 'Los Angeles': 13 | return 475 14 | 15 | def rental_car_cost(days): 16 | total = days*40 17 | if days >= 7: 18 | tuto = total - 50 19 | return tuto 20 | elif days >= 3 and days < 7: 21 | tato = total - 20 22 | return tato 23 | else: 24 | total = days*40 25 | return total 26 | 27 | def trip_cost(city, days, spending_money): 28 | notreal = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money 29 | return notreal 30 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/03 Do the grades vary?/8-Standard Deviation.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | 3 | 4 | def print_grades(grades): 5 | for grade in grades: 6 | print grade 7 | 8 | 9 | def grades_sum(grades): 10 | total = 0 11 | for grade in grades: 12 | total += grade 13 | return total 14 | 15 | 16 | def grades_average(grades): 17 | sum_of_grades = grades_sum(grades) 18 | average = sum_of_grades / float(len(grades)) 19 | return average 20 | 21 | 22 | def grades_variance(grades): 23 | variance = 0 24 | for g in grades: 25 | variance += ((grades_average(grades) - g) ** 2) 26 | return variance / len(grades) 27 | print grades_variance(grades) 28 | 29 | 30 | def grades_std_deviation(variance): 31 | return (variance) ** 0.5 32 | variance = grades_variance(grades) 33 | print grades_std_deviation(variance) 34 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/Using Classes/10-Overriding methods.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | def display_car(self): 9 | return "This is a %s %s with %s MPG." % (self.color, self.model, self.mpg) 10 | 11 | def drive_car(self): 12 | self.condition = "used" 13 | return self.condition 14 | 15 | class ElectricCar(Car): 16 | def __init__(self, model, color, mpg, battery_type): 17 | super(ElectricCar, self).__init__(model, color, mpg) 18 | self.battery_type = battery_type 19 | 20 | def drive_car(self): 21 | self.condition = "like new" 22 | return self.condition 23 | 24 | my_car = ElectricCar("Ford", "black", 95,"molten salt") 25 | print my_car.condition 26 | print my_car.drive_car() 27 | -------------------------------------------------------------------------------- /Unit 04 Functions/02 Taking a Vacation/Planes, Hotels and Automobiles/7-Plan your Trip.py: -------------------------------------------------------------------------------- 1 | def hotel_cost(nights): 2 | return nights*140 3 | print nights*140 4 | 5 | def plane_ride_cost(city): 6 | if city == 'Charlotte': 7 | return 183 8 | elif city == 'Tampa': 9 | return 220 10 | elif city == 'Pittsburgh': 11 | return 222 12 | elif city == 'Los Angeles': 13 | return 475 14 | 15 | def rental_car_cost(days): 16 | total = days*40 17 | if days >= 7: 18 | tuto = total - 50 19 | return tuto 20 | elif days >= 3 and days < 7: 21 | tato = total - 20 22 | return tato 23 | else: 24 | total = days*40 25 | return total 26 | 27 | def trip_cost(city, days, spending_money): 28 | notreal = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money 29 | return notreal 30 | 31 | print trip_cost("Los Angeles", 5, 600) 32 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Hit or Miss/11-Danger, Will Robinson.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0, 5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print_board(board) 13 | 14 | def random_row(board): 15 | return randint(0, len(board) - 1) 16 | 17 | def random_col(board): 18 | return randint(0, len(board[0]) - 1) 19 | 20 | ship_row = random_row(board) 21 | ship_col = random_col(board) 22 | guess_row = int(raw_input("Guess Row:")) 23 | guess_col = int(raw_input("Guess Col:")) 24 | 25 | print ship_row 26 | print ship_col 27 | 28 | # Write your code below! 29 | if guess_row == ship_row and guess_col == ship_col: 30 | print "Congratulations! You sank my battleship!" 31 | else: 32 | print "You missed my battleship!" 33 | board[int(guess_row)][int(guess_col)] = "X" 34 | print_board(board) 35 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/02 Classes/Using Classes/9-Inheritance.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | condition = "new" 3 | def __init__(self, model, color, mpg): 4 | self.model = model 5 | self.color = color 6 | self.mpg = mpg 7 | 8 | def display_car(self): 9 | return "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg)) 10 | 11 | def drive_car(self): 12 | self.condition = "used" 13 | return self.condition 14 | 15 | class ElectricCar(Car): 16 | def __init__(self, model, color, mpg, battery_type): 17 | super(ElectricCar, self).__init__(model, color, mpg) 18 | self.battery_type = battery_type 19 | 20 | def display_car(self): 21 | inherit_Str = super(ElectricCar, self).display_car() 22 | return inherit_Str + "It has a %s battery. " % (self.battery_type) 23 | 24 | my_car = ElectricCar("Folks", "black", 95,"molten salt") 25 | print my_car.display_car() 26 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/02 Just Average/6-Just weight and see.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | # Add your function below! 21 | def average(numbers): 22 | total = sum(numbers) 23 | total = float(total) / float(len(numbers)) 24 | return total 25 | 26 | def get_average(student): 27 | homework = average(student["homework"])* 0.1 28 | quizzes = average(student["quizzes"])* 0.3 29 | tests = average(student["tests"])* 0.6 30 | 31 | avrg = homework + quizzes + tests 32 | return avrg 33 | 34 | 35 | -------------------------------------------------------------------------------- /Unit 11 Introduction to Classes/01 Introduction to classes/Member Variables and Functions/10-Its Not All Animals and Fruits.py: -------------------------------------------------------------------------------- 1 | class ShoppingCart(object): 2 | """Creates shopping cart objects 3 | for users of our fine website.""" 4 | items_in_cart = {} 5 | def __init__(self, customer_name): 6 | self.customer_name = customer_name 7 | 8 | def add_item(self, product, price): 9 | """Add product to the cart.""" 10 | if not product in self.items_in_cart: 11 | self.items_in_cart[product] = price 12 | print product + " added." 13 | else: 14 | print product + " is already in the cart." 15 | 16 | def remove_item(self, product): 17 | """Remove product from the cart.""" 18 | if product in self.items_in_cart: 19 | del self.items_in_cart[product] 20 | print product + " removed." 21 | else: 22 | print product + " is not in the cart." 23 | my_cart = ShoppingCart("arhtur") 24 | my_cart.add_item("Car", 10000) 25 | -------------------------------------------------------------------------------- /Unit 09 Exam Statistics/03 Do the grades vary?/9-Review.py: -------------------------------------------------------------------------------- 1 | grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5] 2 | variance = grades_variance(grades) 3 | 4 | 5 | def print_grades(grades): 6 | for grade in grades: 7 | print grade 8 | 9 | 10 | def grades_sum(grades): 11 | total = 0 12 | for grade in grades: 13 | total += grade 14 | return total 15 | 16 | 17 | def grades_average(grades): 18 | sum_of_grades = grades_sum(grades) 19 | average = sum_of_grades / float(len(grades)) 20 | return average 21 | 22 | 23 | def grades_variance(grades): 24 | variance = 0 25 | for g in grades: 26 | variance += ((grades_average(grades) - g) ** 2) 27 | return variance / float(len(grades)) 28 | print grades_variance(grades) 29 | 30 | 31 | def grades_std_deviation(variance): 32 | return (variance) ** 0.5 33 | variance = float(grades_variance(grades)) 34 | print grades_std_deviation(variance) 35 | 36 | print print_grades(grades) 37 | print grades_sum(grades) 38 | print grades_average(grades) 39 | print grades_variance(grades) 40 | print grades_std_deviation(variance) 41 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Hit or Miss/12-Bad Aim.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(0, 5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print_board(board) 13 | 14 | def random_row(board): 15 | return randint(0, len(board) - 1) 16 | 17 | def random_col(board): 18 | return randint(0, len(board[0]) - 1) 19 | 20 | ship_row = random_row(board) 21 | ship_col = random_col(board) 22 | guess_row = int(raw_input("Guess Row:")) 23 | guess_col = int(raw_input("Guess Col:")) 24 | 25 | print ship_row 26 | print ship_col 27 | 28 | # Write your code below! 29 | if guess_row >= 0 or guess_row <= len(board) and guess_col >= 0 or guess_col<=len(board[0]): 30 | if guess_row == ship_row and guess_col == ship_col: 31 | print "Congratulations! You sank my battleship!" 32 | elif guess_row < 5 and guess_col < 5 : 33 | print "You missed my battleship!" 34 | board[int(guess_row)][int(guess_col)] = "X" 35 | print_board(board) 36 | else: 37 | print "Oops, that's not even in the ocean." 38 | 39 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/02 Just Average/7-Sending a Letter.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | # Add your function below! 21 | def average(numbers): 22 | total = sum(numbers) 23 | total = float(total) / float(len(numbers)) 24 | return total 25 | 26 | def get_average(student): 27 | homework = average(student["homework"])* 0.1 28 | quizzes = average(student["quizzes"])* 0.3 29 | tests = average(student["tests"])* 0.6 30 | 31 | avrg = homework + quizzes + tests 32 | return avrg 33 | 34 | def get_letter_grade(score): 35 | if score>= 90: 36 | return 'A' 37 | elif score>= 80: 38 | return 'B' 39 | elif score>= 70: 40 | return 'C' 41 | elif score >= 60: 42 | return 'D' 43 | else: 44 | return 'F' 45 | 46 | #get_letter_grade 47 | 48 | 49 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Hit or Miss/13-Not Again.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print "Let's play Battleship!" 13 | print_board(board) 14 | 15 | def random_row(board): 16 | return randint(0, len(board) - 1) 17 | 18 | def random_col(board): 19 | return randint(0, len(board[0]) - 1) 20 | 21 | ship_row = random_row(board) 22 | ship_col = random_col(board) 23 | print ship_row 24 | print ship_col 25 | 26 | for turn in range(4): 27 | print "Turn", turn + 1 28 | 29 | guess_row = int(raw_input("Guess Row:")) 30 | guess_col = int(raw_input("Guess Col:")) 31 | 32 | if guess_row == ship_row and guess_col == ship_col: 33 | print "Congratulations! You sunk my battleship!" 34 | else: 35 | if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): 36 | print "Oops, that's not even in the ocean." 37 | elif(board[guess_row][guess_col] == "X"): 38 | print "You guessed that one already." 39 | else: 40 | print "You missed my battleship!" 41 | board[guess_row][guess_col] = "X" 42 | 43 | print_board(board) 44 | 45 | if turn == 3: 46 | print "Game Over" 47 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/Hit or Miss/14-Test Run.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print "Let's play Battleship!" 13 | print_board(board) 14 | 15 | def random_row(board): 16 | return randint(0, len(board) - 1) 17 | 18 | def random_col(board): 19 | return randint(0, len(board[0]) - 1) 20 | 21 | ship_row = random_row(board) 22 | ship_col = random_col(board) 23 | print ship_row 24 | print ship_col 25 | 26 | for turn in range(4): 27 | print "Turn", turn + 1 28 | 29 | guess_row = int(raw_input("Guess Row:")) 30 | guess_col = int(raw_input("Guess Col:")) 31 | 32 | if guess_row == ship_row and guess_col == ship_col: 33 | print "Congratulations! You sunk my battleship!" 34 | else: 35 | if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): 36 | print "Oops, that's not even in the ocean." 37 | elif(board[guess_row][guess_col] == "X"): 38 | print "You guessed that one already." 39 | else: 40 | print "You missed my battleship!" 41 | board[guess_row][guess_col] = "X" 42 | 43 | print_board(board) 44 | 45 | if turn == 3: 46 | print "Game Over" 47 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/You Sunk my Battleship/15-Play it, Sam.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print "Let's play Battleship!" 13 | print_board(board) 14 | 15 | def random_row(board): 16 | return randint(0, len(board) - 1) 17 | 18 | def random_col(board): 19 | return randint(0, len(board[0]) - 1) 20 | 21 | ship_row = random_row(board) 22 | ship_col = random_col(board) 23 | print ship_row 24 | print ship_col 25 | 26 | 27 | for turn in range(4): 28 | print "Turn", turn + 1 29 | # Everything from here on should go in your for loop! 30 | # Be sure to indent four spaces! 31 | guess_row = int(raw_input("Guess Row:")) 32 | guess_col = int(raw_input("Guess Col:")) 33 | 34 | if guess_row == ship_row and guess_col == ship_col: 35 | print "Congratulations! You sunk my battleship!" 36 | else: 37 | if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): 38 | print "Oops, that's not even in the ocean." 39 | elif(board[guess_row][guess_col] == "X"): 40 | print "You guessed that one already." 41 | else: 42 | print "You missed my battleship!" 43 | board[guess_row][guess_col] = "X" 44 | # Print (turn + 1) here! 45 | print_board(board) 46 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/You Sunk my Battleship/18-To Your Battle Stations.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print "Let's play Battleship!" 13 | print_board(board) 14 | 15 | def random_row(board): 16 | return randint(0, len(board) - 1) 17 | 18 | def random_col(board): 19 | return randint(0, len(board[0]) - 1) 20 | 21 | ship_row = random_row(board) 22 | ship_col = random_col(board) 23 | print ship_row 24 | print ship_col 25 | 26 | for turn in range(4): 27 | print "Turn", turn + 1 28 | 29 | guess_row = int(raw_input("Guess Row:")) 30 | guess_col = int(raw_input("Guess Col:")) 31 | 32 | if guess_row == ship_row and guess_col == ship_col: 33 | print "Congratulations! You sunk my battleship!" 34 | break 35 | else: 36 | if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): 37 | print "Oops, that's not even in the ocean." 38 | elif(board[guess_row][guess_col] == "X"): 39 | print "You guessed that one already." 40 | else: 41 | print "You missed my battleship!" 42 | board[guess_row][guess_col] = "X" 43 | 44 | print_board(board) 45 | 46 | if turn == 3: 47 | print "Game Over" 48 | -------------------------------------------------------------------------------- /Unit 07 Lists and Functions/02 Battleship/You Sunk my Battleship/17-A Real Win.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | board = [] 4 | 5 | for x in range(5): 6 | board.append(["O"] * 5) 7 | 8 | def print_board(board): 9 | for row in board: 10 | print " ".join(row) 11 | 12 | print "Let's play Battleship!" 13 | print_board(board) 14 | 15 | def random_row(board): 16 | return randint(0, len(board) - 1) 17 | 18 | def random_col(board): 19 | return randint(0, len(board[0]) - 1) 20 | 21 | ship_row = random_row(board) 22 | ship_col = random_col(board) 23 | print ship_row 24 | print ship_col 25 | 26 | for turn in range(4): 27 | print "Turn", turn + 1 28 | 29 | guess_row = int(raw_input("Guess Row:")) 30 | guess_col = int(raw_input("Guess Col:")) 31 | 32 | if guess_row == ship_row and guess_col == ship_col: 33 | print "Congratulations! You sunk my battleship!" 34 | for turn in range(4): 35 | break 36 | else: 37 | if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4): 38 | print "Oops, that's not even in the ocean." 39 | elif(board[guess_row][guess_col] == "X"): 40 | print "You guessed that one already." 41 | else: 42 | print "You missed my battleship!" 43 | board[guess_row][guess_col] = "X" 44 | 45 | print_board(board) 46 | 47 | if turn == 3: 48 | print "Game Over" 49 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/02 Just Average/9-How is everything doing.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | # Add your function below! 21 | def average(numbers): 22 | total = sum(numbers) 23 | total = float(total) / float(len(numbers)) 24 | return total 25 | 26 | def get_average(student): 27 | homework = average(student["homework"])* 0.1 28 | quizzes = average(student["quizzes"])* 0.3 29 | tests = average(student["tests"])* 0.6 30 | 31 | avrg = homework + quizzes + tests 32 | return avrg 33 | 34 | def get_letter_grade(score): 35 | if score>= 90: 36 | return 'A' 37 | elif score>= 80: 38 | return 'B' 39 | elif score>= 70: 40 | return 'C' 41 | elif score >= 60: 42 | return 'D' 43 | else: 44 | return 'F' 45 | 46 | def get_class_average(students): 47 | results = [] 48 | for student in students: 49 | results.append(get_average(student)) 50 | return average(results) 51 | 52 | students = [lloyd, alice, tyler] 53 | print get_class_average(students) 54 | print get_letter_grade(get_class_average(students)) 55 | -------------------------------------------------------------------------------- /Unit 06 Student Becomes the Teacher/02 Just Average/8-Part of the Whole.py: -------------------------------------------------------------------------------- 1 | lloyd = { 2 | "name": "Lloyd", 3 | "homework": [90.0, 97.0, 75.0, 92.0], 4 | "quizzes": [88.0, 40.0, 94.0], 5 | "tests": [75.0, 90.0] 6 | } 7 | alice = { 8 | "name": "Alice", 9 | "homework": [100.0, 92.0, 98.0, 100.0], 10 | "quizzes": [82.0, 83.0, 91.0], 11 | "tests": [89.0, 97.0] 12 | } 13 | tyler = { 14 | "name": "Tyler", 15 | "homework": [0.0, 87.0, 75.0, 22.0], 16 | "quizzes": [0.0, 75.0, 78.0], 17 | "tests": [100.0, 100.0] 18 | } 19 | 20 | # Add your function below! 21 | def average(numbers): 22 | total = sum(numbers) 23 | total = float(total) / float(len(numbers)) 24 | return total 25 | 26 | def get_average(student): 27 | homework = average(student["homework"])* 0.1 28 | quizzes = average(student["quizzes"])* 0.3 29 | tests = average(student["tests"])* 0.6 30 | 31 | avrg = homework + quizzes + tests 32 | return avrg 33 | 34 | def get_letter_grade(score): 35 | if score>= 90: 36 | return 'A' 37 | elif score>= 80: 38 | return 'B' 39 | elif score>= 70: 40 | return 'C' 41 | elif score >= 60: 42 | return 'D' 43 | else: 44 | return 'F' 45 | 46 | print get_letter_grade(get_average(lloyd)) 47 | print get_letter_grade(get_average(alice)) 48 | print get_letter_grade(get_average(tyler)) 49 | 50 | students=[lloyd, alice, tyler] 51 | 52 | def get_class_average(students): 53 | results=[] 54 | for student in students: 55 | results.append(get_average(student)) 56 | return average(results) 57 | 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codecademy Python Exercises solutions 2 | 3 | This repo include the python excerises from Codecademy, Codecademy is an online interactive platform that offers free coding classes in seven different programming languages including Python, PHP, jQuery, JavaScript, and Ruby, as well as markup languages HTML and CSS. As of January 2014, the site had over 24 million users who had completed over 100 million exercises. 4 | 5 | 6 | # Why Python 7 | 8 | There are many reasons:- 9 | 10 | - Easier to learn which keeps you going to learn anything and everything in Python 11 | - Development is faster than C and Java. In today’s development arena for a company starting up , the main challenge is building the product first and fast and then keep doing the feature enhancements and bug fixing. Python beats C/Java/C# easily in development time. 12 | - Python programmers are less compared to Java/C/C++/C# etc so finding a Python resource is also difficult hence Python developers are often paid higher. 13 | - Strong Python community. From free workshop to Meetups/Mailing Groups/Volunteered Conferences every Python Developer will be willing to help you if you are stuck. 14 | Almost anything that you can think of , is doable in Python. Scraping/Scripting/Web Development/Machine Learning/Data Science/Game Development/Server Automation. 15 | - You will get Python bindings for most of the famous Open Source Libararies easily.(Sign of a active FOSS community) 16 | - Python is scalable and big companies have already started to use it. - Google/Facebook/LinkedIn/NASA/Pinterest/Quora/Instagram/Torrentz/Dropbox/BitBucket/Disqus/Upwork and Countless Startups 17 | - Last but not the least- Once you start learning Python, you will fall in love with it and I bet she will not cheat/dump you and probably you would end up getting married with her. ---- Content from ([Quora.com](https://www.quora.com/How-important-is-it-to-learn-Python-What-are-some-reasons-I-should-learn-Python)) 18 | 19 | should-learn-Python 20 | ## What is there ? 21 | 22 | - Unit 01 Python Syntax 23 | - Unit 02 Strings and Console Output 24 | - Unit 03 Conditionals and Control Flow 25 | - Unit 04 Functions 26 | - Unit 05 Lists & Dictionaries 27 | - Unit 06 Student Becomes the Teacher 28 | - Unit 07 Lists and Functions 29 | - Unit 08 Loops 30 | - Unit 09 Exam Statistics 31 | - Unit 10 Advanced Topics in Python 32 | - Unit 11 Introduction to Classes 33 | - Unit 12 File Input and Output 34 | 35 | # MY Progress in Codecademy Python course 36 | 37 | *I have successfully completed the course on 2013 38 | 39 | ![codeademy](https://user-images.githubusercontent.com/8171465/31173722-2a5dcdb6-a8f8-11e7-9895-67af5ca1ba32.png) 40 | 41 | 42 | #### Thanks 43 | See [Learn Python from Codeacemy ](https://www.codecademy.com/learn/learn-python) 44 | 45 | 46 | 47 | --------------------------------------------------------------------------------