├── .github └── FUNDING.yml ├── 10.1.2 Guess the Word, Part 1.py ├── 10.1.3 Guess the Word, Part 2.py ├── 10.1.4 Guess the Word, Part 3.py ├── 10.1.5 Guess the Word, Part 4.py ├── 11.1.1 Final Exam Pt 1: Multiple Choice ├── 2.1.2 Intro to Tracy ├── 2.1.4 Stretched Slinky.py ├── 2.10.2 Top Down Design ├── 2.10.4 Bubble Wrap 2.0.py ├── 2.10.5 Sidewalk.py ├── 2.11.2 Variables ├── 2.11.4 Dartboard.py ├── 2.11.5 Line of Increasing Blocks.py ├── 2.12.2 User Input ├── 2.12.4 Colored Dartboard.py ├── 2.12.5 Four Corners.py ├── 2.13.2 Parameters ├── 2.13.4 Colorful Caterpillar.py ├── 2.13.5 Circle in a Square.py ├── 2.13.6 Snowman.py ├── 2.14.2 Using i in For Loops ├── 2.14.4 Geometry 2.0.py ├── 2.15.2 Extended Loop Control ├── 2.15.4 Dartboard using i.py ├── 2.15.5 Phone Signal.py ├── 2.16.2 If Statements ├── 2.16.4 Happy Face.py ├── 2.16.5 Black and White Squares.py ├── 2.17.2 If or Else Statements ├── 2.17.4 Rating.py ├── 2.17.5 Happy or Sad Face.py ├── 2.18.2 While Loops ├── 2.18.4 Increasing Squares.py ├── 2.18.5 Guess a Number.py ├── 2.19.2 Putting Together Control Structures ├── 2.19.4 Guess a Number 2.0.py ├── 2.19.5 Circle Pyramid 2.0.py ├── 2.19.6 Checkerboard.py ├── 2.2.2 Tracy's Grid World ├── 2.2.4 Shorter Dashed Line.py ├── 2.2.5 Caterpillar.py ├── 2.20.1 Putting It All Together Quiz ├── 2.3.2 Turning Tracy ├── 2.3.5 Rectangle.py ├── 2.3.6 4 Columns.py ├── 2.4.2 For Loops ├── 2.4.5 Row of Circles ├── 2.4.6 4 Columns 2.0 ├── 2.5.2 Turning Tracy Using Angles ├── 2.5.5 Hexagon.py ├── 2.5.6 'X' Marks the Spot.py ├── 2.5.7 Circle Pyramid.py ├── 2.6.2 Comments ├── 2.6.4 Circle Pyramid with Comments.py ├── 2.7.2 Naming Guidelines ├── 2.8.2 Functions ├── 2.8.4 Beaded Bracelet.py ├── 2.8.5 Shape Stack.py ├── 2.9.2 Artistic Effects ├── 2.9.5 Four Colored Triangles.py ├── 2.9.6 Colorful Bracelet.py ├── 2.9.7 Kid's Shapes Toy.py ├── 3.1.2 Printing in Python ├── 3.1.5 Introduce Yourself.py ├── 3.1.6 Fix This Program!.py ├── 3.1.7 Vertical name.py ├── 3.2.2 Variables and Types ├── 3.2.6 Make Some Variables!.py ├── 3.2.7 Undefined Variables.py ├── 3.3.2 User Input ├── 3.3.6 Hello .py ├── 3.3.7 Age.py ├── 3.4.2 Mathematical Operators ├── 3.4.5 Add Parentheses.py ├── 3.4.8 Rectangle.py ├── 3.5.2 String Operators ├── 3.5.4 Fix This Program.py ├── 3.5.6 Introduce Yourself, Part 2.py ├── 3.5.7 Rectangle, Part 2.py ├── 3.5.8 Rectangle, Part 3.py ├── 3.5.9 Recipe.py ├── 3.6.2 Comments ├── 3.6.5 Add Comments!.py ├── 3.7.1 Basic Python and Console Interaction Quiz ├── 4.1.2 Booleans ├── 4.1.4 Fix This Program.py ├── 4.1.5 Plants.py ├── 4.2.2 If Statements ├── 4.2.5 Fix This Program.py ├── 4.2.6 Is It Raining?.py ├── 4.3.10 Transaction.py ├── 4.3.2 Comparison Operators ├── 4.3.6 Old Enough to Vote?.py ├── 4.3.7 Positive, Zero, or Negative?.py ├── 4.3.9 Table Reservation.py ├── 4.4.2 Logical Operators ├── 4.4.4 Administrators, Teachers, and Students.py ├── 4.4.5 Presidential Eligibility.py ├── 4.4.6 Presidential Eligibility- Extended.py ├── 4.5.2 Floating Point Numbers and Rounding ├── 4.5.4 Correct Portion.py ├── 4.6.1 Conditionals Quiz ├── 5.1.2 While Loops ├── 5.1.6 2 Through 20 Even.py ├── 5.1.7 Divisibility.py ├── 5.2.2 For Loops ├── 5.2.5 Counting 10 to 100 by Tens.py ├── 5.2.8 Average Test Score.py ├── 5.2.9 How Many Names?.py ├── 5.3.2 Break and Continue ├── 5.3.7 Higher or Lower.py ├── 5.4.2 Nested Control Structures ├── 5.4.6 Rolling Dice.py ├── 5.4.7 Categories.py ├── 5.5.1 Looping Unit Test ├── 6.1.2 Functions ├── 6.1.5 Weather.py ├── 6.2.2 Functions and Parameters ├── 6.2.5 Print Product.py ├── 6.2.6 Print Multiple Times.py ├── 6.2.8 Area of a Square with Default Parameters.py ├── 6.3.2 Namespaces in Functions ├── 6.3.5 Fix This Program!.py ├── 6.3.6 Adding to a Value.py ├── 6.3.7 Add, Subtract, or Multiply.py ├── 6.4.2 Functions and Return Values ├── 6.4.8 Sum Two Numbers.py ├── 6.4.9 Temperature Converter.py ├── 6.5.2 Exceptions ├── 6.5.5 Temperature Converter, Part 2.py ├── 6.5.6 Enter a Positive Number.py ├── 6.6.1 Functions and Exceptions Quiz ├── 7.1.2 Indexing ├── 7.1.5 Initials.py ├── 7.1.6 Sandwich Sandwiches.py ├── 7.2.2 Slicing ├── 7.2.6 If You're Not First, You're Last.py ├── 7.2.7 Part 1, Replace a Letter.py ├── 7.2.8 Part 2, Replace a Letter.py ├── 7.3.2 Immutability ├── 7.3.4 Find the Error.py ├── 7.4.2 Strings and For Loops ├── 7.4.4 Length of User's Name.py ├── 7.4.7 Spelling Bee.py ├── 7.4.8 Keeping Count.py ├── 7.5.2 The in Keyword ├── 7.5.5 Contains a Vowel.py ├── 7.6.10 Part 2, Remove All From String.py ├── 7.6.2 String Methods ├── 7.6.4 ENTHUSIASM!.py ├── 7.6.8 What's in a Name?.py ├── 7.6.9 Part 1, Remove All From String.py ├── 7.7.1 Strings Quiz ├── 8.1.10 Coordinate Pairs.py ├── 8.1.2 Tuples ├── 8.1.7 Fix This Tuple.py ├── 8.1.8 Citation.py ├── 8.1.9 Diving Contest.py ├── 8.2.2 Lists ├── 8.2.5 Spell It Out.py ├── 8.2.7 Listed Greeting.py ├── 8.3.5 Max In List.py ├── 8.3.6 Owls.py ├── 8.3.7 Exclamat!on Po!nts.py ├── 8.3.8 Word Ladder.py ├── 8.3.9 Owls, Part 2.py ├── 8.4.11 Take a Thing Out, Sort It and Reverse It.py ├── 8.4.12 Librarian, Part 2.py ├── 8.4.2 List Methods ├── 8.4.4 How Many Names?.py ├── 8.4.5 Five Numbers.py ├── 8.4.7 Librarian.py ├── 8.5.1 Creating and Altering Data Structures Quiz ├── 9.1.2 2d Lists ├── 9.1.6 Checkerboard, v1.py ├── 9.1.7 Checkerboard, v2.py ├── 9.1.8 Checkerboard, v3.py ├── 9.1.9 Tic Tac Toe.py ├── 9.2.2 List Comprehensions ├── 9.2.5 Divisible by 3.py ├── 9.2.8 Last Names.py ├── 9.2.9 Strings To Integers.py ├── 9.3.2 Packing and Unpacking ├── 9.3.6 Coordinate Pair.py ├── 9.3.7 Slopes.py ├── 9.3.9 Full Name & Citation.py ├── 9.4.2 Dictionaries.py ├── 9.4.5 Phone Book.py ├── 9.4.6 Word Counts.py ├── 9.5.2 Equivalence vs. Identity ├── 9.5.6 Swapping.py ├── 9.5.7 Word Counts, Part 2.py ├── 9.6.1 Extending Data Structures Quiz ├── Knowledge & Skills: Python ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: ap_gaming123 2 | -------------------------------------------------------------------------------- /10.1.2 Guess the Word, Part 1.py: -------------------------------------------------------------------------------- 1 | def get_guess(): 2 | while True: 3 | guess = input("Guess: ") 4 | if isinstance(guess, int): 5 | print("Your guess ust be a lowercase letter!") 6 | else: 7 | if guess.islower(): 8 | if len(guess) == 1: 9 | return guess 10 | else: 11 | print("Your guess must have exactly one character!") 12 | 13 | secret_word = "grasswayz" 14 | 15 | while True: 16 | guess = get_guess() 17 | if guess in secret_word: 18 | print("That letter is in the secret word!") 19 | else: 20 | print("That letter is not in the secret word.") 21 | -------------------------------------------------------------------------------- /10.1.3 Guess the Word, Part 2.py: -------------------------------------------------------------------------------- 1 | def get_guess(): 2 | while True: 3 | guess = input("Guess: ") 4 | if len(guess) != 1: 5 | print("Your guess must be a lowercase letter!") 6 | elif not guess.islower(): 7 | print("Your guess must be a lowercase letter!") 8 | else: 9 | return guess 10 | 11 | def update_dashes(secret_word, dashes, guess): 12 | result = "" 13 | for i in range(len(secret_word)): 14 | if secret_word[i] == guess: 15 | result += guess 16 | else: 17 | result += dashes[i] 18 | return result 19 | 20 | 21 | secret_word = "grasswayz" 22 | dashes = "-"*len(secret_word) 23 | while True: 24 | guess = get_guess() 25 | if guess in secret_word: 26 | print("The letter is in the word.") 27 | dashes = update_dashes(secret_word, dashes, guess) 28 | else: 29 | print("That letter is not in the word.") 30 | print(dashes) 31 | -------------------------------------------------------------------------------- /10.1.4 Guess the Word, Part 3.py: -------------------------------------------------------------------------------- 1 | secret_word = "eggplants" 2 | dashes = "---------" 3 | # NOTE: Change the amount of dashes according to how many letters are in the variable 4 | # NOTE CONTINUED: secret word. Make sure to change both top and bottom. 5 | arr = ['-','-','-','-','-','-','-','-','-'] 6 | guesses_left = 10 7 | # NOTE: You can change the number of guesses left according to the number above. 8 | def get_guess(): 9 | while True: 10 | print(''.join(arr)) 11 | print(str(guesses_left) + " incorrect guesses left.") 12 | guess = input("Guess: ") 13 | if len(guess) > 1: 14 | print("Your guess must have exactly one character!") 15 | elif guess not in "abcdefghijklmnopqrstuvwxyz": 16 | print("Your guess must be a lowercase letter!") 17 | else: 18 | return guess 19 | 20 | 21 | while guesses_left > 0 and '-' in arr: 22 | a = get_guess() 23 | for i in range(len(secret_word)): 24 | if secret_word[i] == a: 25 | arr[i] = a 26 | if a not in secret_word: 27 | print("That letter is not in the word!") 28 | guesses_left -= 1 29 | else: 30 | print("That letter is in the word!") 31 | 32 | if '-' not in arr: 33 | print("Congrats you win! The word was: "+ secret_word) 34 | else: 35 | print("You lose, The word was: " + secret_word) 36 | 37 | def update_dashes(): 38 | pass 39 | -------------------------------------------------------------------------------- /10.1.5 Guess the Word, Part 4.py: -------------------------------------------------------------------------------- 1 | import random 2 | words = ["grasswayz", "phases", "paranoia", "felony", "trenches", "bukayo"] 3 | secret_word = random.choice(words) 4 | dashes = "" 5 | arr = [] 6 | for i in range(len(secret_word)): 7 | dashes += '-' 8 | arr.append('-') 9 | 10 | guesses_left = 10 11 | 12 | def get_guess(): 13 | while True: 14 | print(''.join(arr)) 15 | print(str(guesses_left) + " incorrect guesses left.") 16 | guess = input("Guess: ") 17 | if len(guess) > 1: 18 | print("Your guess must have exactly one character!") 19 | elif guess not in "abcdefghijklmnopqrstuvwxyz": 20 | print("Your guess must be a lowercase letter!") 21 | else: 22 | return guess 23 | 24 | 25 | while guesses_left > 0 and '-' in arr: 26 | a = get_guess() 27 | for i in range(len(secret_word)): 28 | if secret_word[i] == a: 29 | arr[i] = a 30 | if a not in secret_word: 31 | print("That letter is not in the word!") 32 | guesses_left -= 1 33 | else: 34 | print("That letter is in the word!") 35 | 36 | if '-' not in arr: 37 | print("Congrats you win! The word was: "+ secret_word) 38 | else: 39 | print("You lose, The word was: " + secret_word) 40 | 41 | def update_dashes(): 42 | pass 43 | -------------------------------------------------------------------------------- /11.1.1 Final Exam Pt 1: Multiple Choice: -------------------------------------------------------------------------------- 1 | 1. It is not raining and 50°F 2 | 2. Diamond Shape Answer 3 | 3. I only 4 | 4. 9 5 | 5. x ≤ 5 6 | 6. 10 7 | 7. A for loop repeats commands a specific number of times and a while loop repeats until a condition becomes false. 8 | 8. TracyTracyTracyTracyTracy 9 | 9. 8 times 10 | 10. 200 11 | 11. int 12 | 12. 5 13 | 13. Maybe 14 | 14. [“blue”, “green”, “orange”, “red”, “yellow”] 15 | 15. 16 | Tracy 17 | Tracy 18 | Turtle 19 | 16. 6 20 | 17. 21 | ribbon_colors = ("blue", "red", "green") 22 | ribbon_colors[2] = "silver" 23 | 18. ['b', 'u', 't', 't', 'e', 'r', 'f', 'l', 'y'] 24 | 19. find 25 | 20. foods[1][0] 26 | 21. [‘Fri’, ‘Thurs’, ‘Wed’, ‘Tues’, ‘Mon’, ‘Sat’, ‘Sun’] 27 | 22. a 28 | 23. Any parameters that don’t have default values must come before any parameters that do have default values 29 | 24. len(animals[cur]) <= 8 30 | 25. You have ordered the following item: 3 31 | -------------------------------------------------------------------------------- /2.1.2 Intro to Tracy: -------------------------------------------------------------------------------- 1 | 1. forward(100) 2 | 2. The radius of the circle 3 | 3. The bottom of the circle 4 | -------------------------------------------------------------------------------- /2.1.4 Stretched Slinky.py: -------------------------------------------------------------------------------- 1 | circle(35) 2 | forward(40) 3 | circle(35) 4 | forward(40) 5 | circle(35) 6 | forward(40) 7 | circle(35) 8 | forward(40) 9 | circle(35) 10 | forward(40) 11 | -------------------------------------------------------------------------------- /2.10.2 Top Down Design: -------------------------------------------------------------------------------- 1 | 1. Breaking the problem down into smaller parts 2 | 2. Using descriptive names for variables 3 | -------------------------------------------------------------------------------- /2.10.4 Bubble Wrap 2.0.py: -------------------------------------------------------------------------------- 1 | """ 2 | This code will fill the canvas with light blue circles. 3 | 4 | Now add a function that will draw a white highlight on each bubble. 5 | """ 6 | speed(0) 7 | 8 | # This function will draw one row of 10 circles 9 | def draw_circle_row(): 10 | for i in range(10): 11 | pendown() 12 | begin_fill() 13 | color("light blue") 14 | circle(20) 15 | end_fill() 16 | penup() 17 | forward(40) 18 | 19 | # This function will move Tracy from end of row up to beginning of the row on top 20 | def move_up_a_row(): 21 | left(90) 22 | forward(40) 23 | right(90) 24 | backward(400) 25 | 26 | def make_highlight(): 27 | for i in range(10): 28 | pendown() 29 | pensize(2) 30 | color("white") 31 | circle(10, 90) 32 | pensize(1) 33 | penup() 34 | backward(50) 35 | right(90) 36 | backward(10) 37 | 38 | # Send Tracy to starting position in bottom left corner 39 | penup() 40 | setposition(-180,-200) 41 | 42 | # Call circle drawing function 10 times to fill ten rows 43 | for i in range(10): 44 | draw_circle_row() 45 | move_up_a_row() 46 | 47 | left(90) 48 | setposition(-170, 180) 49 | for i in range(10): 50 | make_highlight() 51 | right(90) 52 | move_up_a_row() 53 | left(90) 54 | -------------------------------------------------------------------------------- /2.10.5 Sidewalk.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | 3 | def draw_square(): 4 | pendown() 5 | forward(50) 6 | left(90) 7 | forward(50) 8 | left(90) 9 | forward(50) 10 | left(90) 11 | forward(50) 12 | left(90) 13 | penup() 14 | forward(50) 15 | penup() 16 | setposition(-200,-200) 17 | pendown() 18 | 19 | for i in range(8): 20 | draw_square() 21 | left(90) 22 | forward(50) 23 | 24 | for i in range(7): 25 | draw_square() 26 | left(90) 27 | 28 | for i in range(8): 29 | draw_square() 30 | left(90) 31 | for I in range(7): 32 | draw_square() 33 | -------------------------------------------------------------------------------- /2.11.2 Variables: -------------------------------------------------------------------------------- 1 | 1. Store information to use in our programs 2 | 2. 3 | distance = 10 4 | forward(distance) 5 | left(90) 6 | distance = distance * 2 7 | forward(distance) 8 | 3. 9 | square_length = 20 10 | 11 | for i in range(4): 12 | for i in range(4): 13 | forward(square_length) 14 | left(90) 15 | square_length = square_length * 2 16 | -------------------------------------------------------------------------------- /2.11.4 Dartboard.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | circle_radius=25 3 | def center_circle(): 4 | right(90) 5 | forward(25) 6 | left(90) 7 | 8 | for i in range(4): 9 | pendown() 10 | circle(circle_radius) 11 | penup() 12 | center_circle() 13 | circle_radius = circle_radius + 25 14 | -------------------------------------------------------------------------------- /2.11.5 Line of Increasing Blocks.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | square_length=10 3 | distance=20 4 | def draw_square(): 5 | pendown() 6 | for i in range(4): 7 | forward(square_length) 8 | left(90) 9 | 10 | penup() 11 | setposition(-150,0) 12 | for i in range(5): 13 | draw_square() 14 | penup() 15 | forward(distance) 16 | square_length=square_length + 10 17 | distance=distance+20 18 | -------------------------------------------------------------------------------- /2.12.2 User Input: -------------------------------------------------------------------------------- 1 | 1. radius = int(input("What is the radius?: ")) 2 | 2. user_color = input("Give a color: ") 3 | 3. The word color is already used as a Tracy command 4 | -------------------------------------------------------------------------------- /2.12.4 Colored Dartboard.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | circle_radius=100 3 | def center_circle(): 4 | right(90) 5 | forward(-25) 6 | left(90) 7 | def draw_circle(): 8 | begin_fill() 9 | color(color_choice) 10 | circle(circle_radius) 11 | end_fill() 12 | penup() 13 | setposition(0,-100) 14 | for i in range(4): 15 | pendown() 16 | color_choice = input("What is the color of the circle? ") 17 | draw_circle() 18 | penup() 19 | center_circle() 20 | circle_radius = circle_radius - 25 21 | -------------------------------------------------------------------------------- /2.12.5 Four Corners.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | square_length = int(input("How large should the squares be? (in pixels): ")) 3 | 4 | 5 | def draw_square(): 6 | for i in range(4): 7 | pendown() 8 | forward(square_length) 9 | right(90) 10 | penup() 11 | penup() 12 | setposition(100,100) 13 | draw_square() 14 | 15 | setposition(100,-100) 16 | draw_square() 17 | 18 | setposition(-150, 100) 19 | draw_square() 20 | 21 | setposition(-150, -100) 22 | draw_square() 23 | -------------------------------------------------------------------------------- /2.13.2 Parameters: -------------------------------------------------------------------------------- 1 | 1. They allow us to tailor functions to be used in multiple situations 2 | 2. As many as we need 3 | 3. 4 | def make_square(length): 5 | for i in range(4): 6 | forward(length) 7 | left(90) 8 | make_square(50) 9 | -------------------------------------------------------------------------------- /2.13.4 Colorful Caterpillar.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | color_choice1 = input("What is the color of the first circle? ") 3 | color_choice2 = input("What is the color of the second circle? ") 4 | color_choice3 = input("What is the color of the third circle? ") 5 | color_choice4 = input("What is the color of the fourth circle? ") 6 | 7 | 8 | 9 | 10 | def draw_circle(): 11 | pendown() 12 | circle(20) 13 | penup() 14 | forward(40) 15 | penup() 16 | setposition(-150,0) 17 | for i in range(2): 18 | begin_fill() 19 | color(color_choice1) 20 | draw_circle() 21 | end_fill() 22 | begin_fill() 23 | color(color_choice2) 24 | draw_circle() 25 | end_fill() 26 | begin_fill() 27 | color(color_choice3) 28 | draw_circle() 29 | end_fill() 30 | begin_fill() 31 | color(color_choice4) 32 | draw_circle() 33 | end_fill() 34 | -------------------------------------------------------------------------------- /2.13.5 Circle in a Square.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | radius = int(input("What is the circle's radius?: ")) 3 | square_color_choice = input("What is the color of the square? ") 4 | 5 | circle_color_choice = input("What is the color of the circle? ") 6 | 7 | def draw_square(): 8 | for i in range(4): 9 | pendown() 10 | begin_fill() 11 | color(square_color_choice) 12 | forward(radius*2) 13 | end_fill() 14 | right(90) 15 | 16 | def draw_circle(): 17 | pendown() 18 | begin_fill() 19 | color(circle_color_choice) 20 | circle(radius) 21 | end_fill() 22 | 23 | penup() 24 | setposition(-radius, radius) 25 | draw_square() 26 | penup() 27 | setposition(0, - radius) 28 | draw_circle() 29 | -------------------------------------------------------------------------------- /2.13.6 Snowman.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | first_radius = int(input("How big should the first circle be? " )) 3 | 4 | 5 | 6 | 7 | def draw_circle(): 8 | pendown() 9 | begin_fill() 10 | color("gray") 11 | circle(first_radius) 12 | end_fill() 13 | penup() 14 | setposition(0,-200) 15 | for i in range(3): 16 | draw_circle() 17 | left(90) 18 | forward(first_radius*2) 19 | right(90) 20 | first_radius = first_radius/2 21 | -------------------------------------------------------------------------------- /2.14.2 Using i in For Loops: -------------------------------------------------------------------------------- 1 | 1. 0 2 | 2. 0, 1, 2 3 | 3. Tracy will turn 90 degrees to the right 4 | -------------------------------------------------------------------------------- /2.14.4 Geometry 2.0.py: -------------------------------------------------------------------------------- 1 | circle_radius = 20 2 | 3 | 4 | 5 | penup() 6 | setposition (0,-100) 7 | for i in range(7): 8 | pendown() 9 | circle(circle_radius,360,i) 10 | circle_radius = circle_radius + 20 11 | penup() 12 | -------------------------------------------------------------------------------- /2.15.2 Extended Loop Control: -------------------------------------------------------------------------------- 1 | 1. 2, 4, 6, 8 2 | 2. image with 4 circles that are evenly spaced out. 3 | -------------------------------------------------------------------------------- /2.15.4 Dartboard using i.py: -------------------------------------------------------------------------------- 1 | for i in range(25,125,25): 2 | pendown() 3 | circle(i) 4 | penup() 5 | right(90) 6 | forward(25) 7 | left(90) 8 | -------------------------------------------------------------------------------- /2.15.5 Phone Signal.py: -------------------------------------------------------------------------------- 1 | for i in range(10,60,10): 2 | pendown() 3 | forward(10) 4 | left(90) 5 | forward(i) 6 | left(90) 7 | forward(10) 8 | left(90) 9 | forward(i) 10 | penup() 11 | left(90) 12 | forward(25) 13 | -------------------------------------------------------------------------------- /2.16.2 If Statements: -------------------------------------------------------------------------------- 1 | 1. To have Tracy make decisions based on conditional statements 2 | 2. Tracy skips the commands under the if statement 3 | 3. 4 | if count > 0: 5 | pendown() 6 | 4. != 7 | 5. 100 pixels 8 | -------------------------------------------------------------------------------- /2.16.4 Happy Face.py: -------------------------------------------------------------------------------- 1 | def smile_mouth(): 2 | pendown() 3 | pensize(6) 4 | forward(4) 5 | left(3) 6 | happy = input("happy or not?") 7 | if happy == "happy": 8 | penup() 9 | setposition(0,-100) 10 | pendown() 11 | begin_fill() 12 | color("yellow") 13 | circle(100) 14 | end_fill() 15 | penup() 16 | setposition(-25,50) 17 | pendown() 18 | begin_fill() 19 | color("black") 20 | circle(10) 21 | end_fill() 22 | penup() 23 | setposition(25,50) 24 | pendown() 25 | begin_fill() 26 | color("black") 27 | circle(10) 28 | end_fill() 29 | penup() 30 | setposition(-75,0) 31 | right(90) 32 | 33 | for i in range(60): 34 | smile_mouth() 35 | -------------------------------------------------------------------------------- /2.16.5 Black and White Squares.py: -------------------------------------------------------------------------------- 1 | penup() 2 | setposition (-50,0) 3 | count = 1 4 | def draw_square(): 5 | for i in range(4): 6 | pendown() 7 | forward(25) 8 | left(90) 9 | penup() 10 | forward(35) 11 | 12 | for i in range(6): 13 | if count % 2 == 0: 14 | draw_square() 15 | count = count - 1 16 | else: 17 | begin_fill() 18 | color("black") 19 | draw_square() 20 | end_fill() 21 | count = count + 1 22 | -------------------------------------------------------------------------------- /2.17.2 If or Else Statements: -------------------------------------------------------------------------------- 1 | 1. If it is raining, bring an umbrella. If not, wear sunglasses. 2 | 2. unlimited 3 | 3. 4 | if count > 10: 5 | forward(100) 6 | else: 7 | forward(50) 8 | 4. 10 pixels 9 | -------------------------------------------------------------------------------- /2.17.4 Rating.py: -------------------------------------------------------------------------------- 1 | rating = int(input("Pick a number 1-10")) 2 | 3 | def draw_x(): 4 | pensize(10) 5 | color("red") 6 | for i in range(4): 7 | right(45) 8 | forward(50) 9 | backward(50) 10 | right(45) 11 | def draw_line(): 12 | pensize(10) 13 | color("yellow") 14 | forward(50) 15 | backward(100) 16 | def draw_checkmark(): 17 | color("green") 18 | pensize(10) 19 | left(45) 20 | forward(75) 21 | backward(75) 22 | left(90) 23 | forward(30) 24 | if rating <=4: 25 | draw_x() 26 | elif rating<=7: 27 | draw_line() 28 | else: 29 | draw_checkmark() 30 | -------------------------------------------------------------------------------- /2.17.5 Happy or Sad Face.py: -------------------------------------------------------------------------------- 1 | def smile_mouth(): 2 | pendown() 3 | pensize(6) 4 | forward(4) 5 | left(3) 6 | def frown_mouth(): 7 | pendown() 8 | pensize(6) 9 | forward(-4) 10 | left(-3) 11 | happy = input("happy or not?") 12 | if happy == "happy": 13 | penup() 14 | setposition(0,-100) 15 | pendown() 16 | begin_fill() 17 | color("yellow") 18 | circle(100) 19 | end_fill() 20 | penup() 21 | setposition(-25,50) 22 | pendown() 23 | begin_fill() 24 | color("black") 25 | circle(10) 26 | end_fill() 27 | penup() 28 | setposition(25,50) 29 | pendown() 30 | begin_fill() 31 | color("black") 32 | circle(10) 33 | end_fill() 34 | penup() 35 | setposition(-75,0) 36 | right(90) 37 | for i in range(60): 38 | smile_mouth() 39 | else: 40 | penup() 41 | setposition(0,-100) 42 | pendown() 43 | begin_fill() 44 | color("yellow") 45 | circle(100) 46 | end_fill() 47 | penup() 48 | setposition(-25,50) 49 | pendown() 50 | begin_fill() 51 | color("black") 52 | circle(10) 53 | end_fill() 54 | penup() 55 | setposition(25,50) 56 | pendown() 57 | begin_fill() 58 | color("black") 59 | circle(10) 60 | end_fill() 61 | penup() 62 | setposition(-75,-50) 63 | right(90) 64 | 65 | for i in range(60): 66 | frown_mouth() 67 | -------------------------------------------------------------------------------- /2.18.2 While Loops: -------------------------------------------------------------------------------- 1 | 1. To repeat code when the number of times to repeat is unknown 2 | 2. By using a condition that will never become false in a while loop 3 | 3. An infinite loop will occur. 4 | 4. image of a **FULL SPIRAL**. 5 | -------------------------------------------------------------------------------- /2.18.4 Increasing Squares.py: -------------------------------------------------------------------------------- 1 | length = 25 2 | speed(0) 3 | 4 | 5 | penup() 6 | backward(10) 7 | def draw_square(): 8 | pendown() 9 | for i in range(4): 10 | forward(length) 11 | left(90) 12 | forward(length/2) 13 | penup() 14 | right(90) 15 | forward(12.5) 16 | left(90) 17 | 18 | 19 | while length<= 350: 20 | draw_square() 21 | length=length+25 22 | backward(length/2) 23 | 24 | 25 | draw_square() 26 | -------------------------------------------------------------------------------- /2.18.5 Guess a Number.py: -------------------------------------------------------------------------------- 1 | secret_number=5 2 | user_number=int(input("Pick a number 1-10")) 3 | 4 | def draw_checkmark(): 5 | color("green") 6 | pensize(10) 7 | left(45) 8 | forward(75) 9 | backward(75) 10 | left(90) 11 | forward(30) 12 | 13 | while user_number != 5: 14 | if user_number != 5: 15 | user_number=int(input("wrong number, try again!")) 16 | elif user_number == 5: 17 | draw_checkmark() 18 | -------------------------------------------------------------------------------- /2.19.2 Putting Together Control Structures: -------------------------------------------------------------------------------- 1 | 1. A only 2 | 2. If/else statements can be used inside for loops. 3 | 3. the img where the turtle is at the bottom left-hand corner 4 | -------------------------------------------------------------------------------- /2.19.4 Guess a Number 2.0.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | secret_number = 5 3 | pensize(10) 4 | 5 | def green_check(): 6 | color("green") 7 | penup() 8 | backward(25) 9 | right(45) 10 | pendown() 11 | forward(35) 12 | left(90) 13 | forward(75) 14 | 15 | def draw_arrow(): 16 | color("red") 17 | left(90) 18 | forward(50) 19 | left(45) 20 | backward(25) 21 | forward(25) 22 | right(90) 23 | backward(25) 24 | forward(25) 25 | left(45) 26 | backward(100) 27 | forward(50) 28 | right(90) 29 | 30 | user_number = int(input("Guess a number between 1 and 10: ")) 31 | 32 | while user_number != secret_number: 33 | if user_number < secret_number: 34 | draw_arrow() 35 | else: 36 | left(180) 37 | draw_arrow() 38 | right(180) 39 | user_number = int(input("Guess a number between 1 and 10: ")) 40 | clear() 41 | 42 | green_check() 43 | -------------------------------------------------------------------------------- /2.19.5 Circle Pyramid 2.0.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | penup() 3 | row_value=0 4 | radius = 25 5 | 6 | 7 | def move_to_row(num_blocks): 8 | x_value = -((num_blocks*50)/2) + radius 9 | y_value = -200+(50*row_value) 10 | setposition(x_value,y_value) 11 | 12 | 13 | def draw_block_row(num_blocks): 14 | for i in range(num_blocks): 15 | pendown() 16 | circle(radius) 17 | penup() 18 | forward(50) 19 | 20 | 21 | num_blocks=int(input("How many blocks on the bottom row? (8 or less): ")) 22 | 23 | 24 | for i in range(num_blocks): 25 | move_to_row(num_blocks) 26 | row_value=row_value+1 27 | draw_block_row(num_blocks) 28 | num_blocks=num_blocks-1 29 | -------------------------------------------------------------------------------- /2.19.6 Checkerboard.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | penup() 3 | setposition (-200,-200) 4 | count = 1 5 | def draw_square(): 6 | for i in range(4): 7 | pendown() 8 | forward(40) 9 | left(90) 10 | penup() 11 | forward(40) 12 | 13 | 14 | for i in range(10): 15 | for i in range(10): 16 | if count % 2 == 0: 17 | begin_fill() 18 | color("black") 19 | draw_square() 20 | end_fill() 21 | count = count - 1 22 | else: 23 | begin_fill() 24 | color("red") 25 | draw_square() 26 | end_fill() 27 | count = count + 1 28 | penup() 29 | left(90) 30 | forward(40) 31 | left(90) 32 | forward(400) 33 | right(180) 34 | count = count + 1 35 | -------------------------------------------------------------------------------- /2.2.2 Tracy's Grid World: -------------------------------------------------------------------------------- 1 | 1. At the (0,0) coordinate in the middle of the canvas 2 | 2. 400 pixels x 400 pixels 3 | 3. A and B 4 | 4. 200 pixels 5 | 5. 6 | penup() 7 | forward(100) 8 | -------------------------------------------------------------------------------- /2.2.4 Shorter Dashed Line.py: -------------------------------------------------------------------------------- 1 | penup() 2 | backward(200) 3 | pendown() 4 | forward(50) 5 | penup() 6 | forward(50) 7 | pendown() 8 | forward(50) 9 | penup() 10 | forward(50) 11 | pendown() 12 | forward(50) 13 | penup() 14 | forward(50) 15 | pendown() 16 | forward(50) 17 | penup() 18 | forward(50) 19 | -------------------------------------------------------------------------------- /2.2.5 Caterpillar.py: -------------------------------------------------------------------------------- 1 | circle(20) 2 | penup() 3 | forward(40) 4 | pendown() 5 | circle(20) 6 | penup() 7 | forward(40) 8 | pendown() 9 | circle(20) 10 | penup() 11 | forward(40) 12 | pendown() 13 | circle(20) 14 | penup() 15 | forward(40) 16 | pendown() 17 | circle(20) 18 | -------------------------------------------------------------------------------- /2.20.1 Putting It All Together Quiz: -------------------------------------------------------------------------------- 1 | 1. 50 spaces 2 | 2. As many times as you want 3 | 3. You want Tracy to draw a blue line, and your program requires lots of blue lines. 4 | 4. 5 | forward(30) 6 | color("blue") 7 | left(180) 8 | 9 | forward(30) 10 | color("green") 11 | left(180) 12 | 13 | forward(30) 14 | color("orange") 15 | left(180) 16 | 5. 17 | # Has Tracy draw a single triangle 18 | def make_triangle(): 19 | 6. turn 20 | 7. Indentation always matters in Python. Every statement must be aligned correctly. 21 | 8. A, C, and F 22 | 9. 23 | def draw_edge(): 24 | forward(100) 25 | left(90) 26 | 10. Functions let you execute code a fixed number of times. 27 | 11. Defining a function means you are teaching the computer a new word. Calling a function means you are commanding the computer to complete defined actions. 28 | 12. How far Tracy is supposed to move 29 | 13. A for loop 30 | 14. right(180) 31 | 15. 32 | # Draw a square 33 | for i in range(4): 34 | left(90) 35 | forward(90) 36 | 16. 37 | for i in range(4): 38 | circle(50, 360, 4) 39 | 17. A triangle 40 | 18. 41 | radius = 50 42 | circle(radius) 43 | 19. 44 | Yes 45 | radius = int(input("Radius: ")) 46 | 47 | circle(radius) 48 | 20. 49 | def draw_circle(color_choice): 50 | pendown() 51 | color(color_choice) 52 | begin_fill() 53 | circle(50) 54 | end_fill() 55 | penup() 56 | forward(100) 57 | draw_circle("red") 58 | draw_circle("blue") 59 | draw_circle("yellow") 60 | 21. Two shapes- a triangle (3 sides) and a pentagon (5 sides). 61 | 22. 10, 20, 30, 40, 50 62 | 23. backward(201) 63 | 24. backward(10) 64 | 25. An infinite loop will occur 65 | -------------------------------------------------------------------------------- /2.3.2 Turning Tracy: -------------------------------------------------------------------------------- 1 | 1. East 2 | 2. A and C 3 | 3. Up 4 | -------------------------------------------------------------------------------- /2.3.5 Rectangle.py: -------------------------------------------------------------------------------- 1 | forward(50) 2 | left(90) 3 | forward(100) 4 | left(90) 5 | forward(50) 6 | left(90) 7 | forward(100) 8 | left(90) 9 | -------------------------------------------------------------------------------- /2.3.6 4 Columns.py: -------------------------------------------------------------------------------- 1 | pendown() 2 | left(90) 3 | backward(200) 4 | forward(400) 5 | left(90) 6 | penup() 7 | forward(100) 8 | left(90) 9 | pendown() 10 | forward(400) 11 | left(90) 12 | penup() 13 | forward(200) 14 | left(90) 15 | pendown() 16 | forward(400) 17 | backward(400) 18 | left(180) 19 | penup() 20 | -------------------------------------------------------------------------------- /2.4.2 For Loops: -------------------------------------------------------------------------------- 1 | 1. Loops let us make shapes of multiple sizes 2 | 2. 3 lines 3 | 3. 8 times 4 | 4. 3, 4, and 5 5 | 5. To show that they are recognized as keywords 6 | -------------------------------------------------------------------------------- /2.4.5 Row of Circles: -------------------------------------------------------------------------------- 1 | penup() 2 | backward(200) 3 | forward(10) 4 | for i in range(20): 5 | pendown() 6 | circle(10) 7 | penup() 8 | forward(20) 9 | -------------------------------------------------------------------------------- /2.4.6 4 Columns 2.0: -------------------------------------------------------------------------------- 1 | penup() 2 | backward (100) 3 | for i in range(3): 4 | pendown() 5 | left(90) 6 | forward (400) 7 | backward (600) 8 | forward (200) 9 | right(90) 10 | penup() 11 | forward (100) 12 | -------------------------------------------------------------------------------- /2.5.2 Turning Tracy Using Angles: -------------------------------------------------------------------------------- 1 | 1. She will turn around 2 | 2. does not turn her 3 | 3. 0 4 | 4. The circle’s diameter 5 | -------------------------------------------------------------------------------- /2.5.5 Hexagon.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | for i in range(6): 3 | forward(50) 4 | left(60) 5 | -------------------------------------------------------------------------------- /2.5.6 'X' Marks the Spot.py: -------------------------------------------------------------------------------- 1 | left(45) 2 | for i in range(4): 3 | left(90) 4 | forward(100) 5 | backward(100) 6 | -------------------------------------------------------------------------------- /2.5.7 Circle Pyramid.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | penup() 3 | setposition(0,-30) 4 | pendown() 5 | circle(50) 6 | penup() 7 | setposition(-50,-115) 8 | for i in range(2): 9 | pendown() 10 | circle(50) 11 | penup() 12 | forward(100) 13 | setposition(-100,-200) 14 | for i in range(3): 15 | pendown() 16 | circle(50) 17 | penup() 18 | forward(100) 19 | -------------------------------------------------------------------------------- /2.6.2 Comments: -------------------------------------------------------------------------------- 1 | 1. Written for humans to read and understand 2 | 2. # 3 | 3. """ 4 | -------------------------------------------------------------------------------- /2.6.4 Circle Pyramid with Comments.py: -------------------------------------------------------------------------------- 1 | """ 2 | circle pyramids are pretty cool 3 | """ 4 | #Will draw a pyramid made of circles with three rows 5 | #Resets da code too make it as fast as possible 6 | speed(0) 7 | penup() 8 | #Creates da first circle for the first row of da circle pyramid and moves it in da first position 9 | setposition(0,-30) 10 | pendown() 11 | circle(50) 12 | penup() 13 | #Creates da second row of circles for da circle pyramid and uses a for loop 14 | setposition(-50,-115) 15 | for i in range(2): 16 | pendown() 17 | circle(50) 18 | penup() 19 | forward(100) 20 | #Creates da final row for da circle pyramid and also uses a for loop 21 | setposition(-100,-200) 22 | for i in range(3): 23 | pendown() 24 | circle(50) 25 | penup() 26 | forward(100) 27 | 28 | -------------------------------------------------------------------------------- /2.7.2 Naming Guidelines: -------------------------------------------------------------------------------- 1 | 1. make_square 2 | 2. draw_squares 3 | -------------------------------------------------------------------------------- /2.8.2 Functions: -------------------------------------------------------------------------------- 1 | 1. Each function only contains one command 2 | 2. A function name and commands to be performed 3 | 3. three_circles() 4 | -------------------------------------------------------------------------------- /2.8.4 Beaded Bracelet.py: -------------------------------------------------------------------------------- 1 | def small_circle(): 2 | circle(10) 3 | left(10) 4 | penup() 5 | forward(20) 6 | pendown() 7 | 8 | penup() 9 | backward (100) 10 | right(90) 11 | 12 | 13 | pendown() 14 | for i in range (36): 15 | small_circle() 16 | penup() 17 | setposition(0,0) 18 | -------------------------------------------------------------------------------- /2.8.5 Shape Stack.py: -------------------------------------------------------------------------------- 1 | speed(5) 2 | 3 | def draw_square(): 4 | pendown() 5 | forward(50) 6 | left(90) 7 | forward(50) 8 | left(90) 9 | forward(50) 10 | left(90) 11 | forward(50) 12 | penup() 13 | left(90) 14 | forward(25) 15 | left(90) 16 | forward(50) 17 | right(90) 18 | def draw_circle(): 19 | pendown() 20 | circle(25) 21 | penup() 22 | left(90) 23 | forward(50) 24 | right(90) 25 | backward(25) 26 | 27 | penup() 28 | setposition(-25,-200) 29 | for i in range(4): 30 | draw_square() 31 | draw_circle() 32 | -------------------------------------------------------------------------------- /2.9.2 Artistic Effects: -------------------------------------------------------------------------------- 1 | 1. 2 | color(“yellow”) 3 | pensize(10) 4 | 2. The color name must be in quotation marks 5 | 3. 6 | begin_fill() 7 | circle(20) 8 | end_fill() 9 | 4. pentagon 10 | 5. half of a hexagon 11 | -------------------------------------------------------------------------------- /2.9.5 Four Colored Triangles.py: -------------------------------------------------------------------------------- 1 | pensize(5) 2 | color("red") 3 | backward(100) 4 | forward(200) 5 | 6 | for i in range(4): 7 | left(125) 8 | color("blue") 9 | forward(50) 10 | left(115) 11 | color("green") 12 | forward(50) 13 | right(240) 14 | -------------------------------------------------------------------------------- /2.9.6 Colorful Bracelet.py: -------------------------------------------------------------------------------- 1 | def small_circle(): 2 | circle(10) 3 | left(10) 4 | penup() 5 | forward(20) 6 | pendown() 7 | 8 | penup() 9 | backward (100) 10 | right(90) 11 | 12 | pendown() 13 | for i in range (12): 14 | color("purple") 15 | begin_fill() 16 | small_circle() 17 | end_fill() 18 | color("blue") 19 | begin_fill() 20 | small_circle() 21 | end_fill() 22 | color("red") 23 | begin_fill() 24 | small_circle() 25 | end_fill() 26 | penup() 27 | setposition(0,0) 28 | -------------------------------------------------------------------------------- /2.9.7 Kid's Shapes Toy.py: -------------------------------------------------------------------------------- 1 | speed(0) 2 | def draw_semicircle(): 3 | color("yellow") 4 | begin_fill() 5 | circle(60,180) 6 | end_fill() 7 | 8 | penup() 9 | setposition(65, 45) 10 | color("blue") 11 | begin_fill() 12 | circle(60) 13 | end_fill() 14 | penup() 15 | setposition(-95,45) 16 | pendown() 17 | color("red") 18 | begin_fill() 19 | circle(60,360,4) 20 | end_fill() 21 | penup() 22 | setposition(-95,-95) 23 | pendown() 24 | draw_semicircle() 25 | penup() 26 | setposition(65, -95) 27 | pendown 28 | color("green") 29 | begin_fill() 30 | circle(60,360,5) 31 | end_fill() 32 | -------------------------------------------------------------------------------- /3.1.2 Printing in Python: -------------------------------------------------------------------------------- 1 | 1. print("Hello, world!") 2 | 2. 3 | Hello 4 | World 5 | -------------------------------------------------------------------------------- /3.1.5 Introduce Yourself.py: -------------------------------------------------------------------------------- 1 | print('') 2 | print('I like writing Python programs!') 3 | -------------------------------------------------------------------------------- /3.1.6 Fix This Program!.py: -------------------------------------------------------------------------------- 1 | print("Hi there!") 2 | print("My favorite color is magenta.") 3 | -------------------------------------------------------------------------------- /3.1.7 Vertical name.py: -------------------------------------------------------------------------------- 1 | print("M") 2 | print("a") 3 | print("r") 4 | print("i") 5 | print("a") 6 | -------------------------------------------------------------------------------- /3.2.2 Variables and Types: -------------------------------------------------------------------------------- 1 | 1. string 2 | 2. 3 | I am 4 | 6 5 | feet tall 6 | -------------------------------------------------------------------------------- /3.2.6 Make Some Variables!.py: -------------------------------------------------------------------------------- 1 | name = "Keisha" 2 | num = 100 3 | print("name") 4 | print("num") 5 | -------------------------------------------------------------------------------- /3.2.7 Undefined Variables.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | print(a) 3 | #comment 4 | b = 20 5 | print(b) 6 | 7 | c = 30 8 | print(c) 9 | 10 | d = 40 11 | print(d) 12 | 13 | e = 50 14 | print(e) 15 | -------------------------------------------------------------------------------- /3.3.2 User Input: -------------------------------------------------------------------------------- 1 | 1. string 2 | 2. Delaware ratified the U.S. Constitution in 1787. 3 | -------------------------------------------------------------------------------- /3.3.6 Hello .py: -------------------------------------------------------------------------------- 1 | user_name = input("what is your name?") 2 | print("Hello " + user_name) 3 | -------------------------------------------------------------------------------- /3.3.7 Age.py: -------------------------------------------------------------------------------- 1 | user_age = int(input("What is your age?: ")) 2 | 3 | user_age = user_age + 1 4 | user_age = str(user_age) 5 | print("You will need " + user_age + " candles") 6 | -------------------------------------------------------------------------------- /3.4.2 Mathematical Operators: -------------------------------------------------------------------------------- 1 | 1. 12 2 | 2. 0 3 | -------------------------------------------------------------------------------- /3.4.5 Add Parentheses.py: -------------------------------------------------------------------------------- 1 | print(2 + 3 *(4 + 8)) 2 | -------------------------------------------------------------------------------- /3.4.8 Rectangle.py: -------------------------------------------------------------------------------- 1 | #MAKES THE VARIABLES 2 | 3 | length = 10 4 | width = 5 5 | 6 | 7 | 8 | 9 | #DOES THE MATH 10 | 11 | 12 | area = length*width 13 | perimeter = 2*(length+width) 14 | 15 | 16 | 17 | 18 | #PRINTSSS 19 | 20 | print(area) 21 | print(perimeter) 22 | -------------------------------------------------------------------------------- /3.5.2 String Operators: -------------------------------------------------------------------------------- 1 | 1. 2 | x = 4 3 | y = 5 4 | print(x + y) 5 | 2. 6 | var = "hello" 7 | print(var) 8 | print(var) 9 | print(var) 10 | -------------------------------------------------------------------------------- /3.5.4 Fix This Program.py: -------------------------------------------------------------------------------- 1 | instrument = "kazoo" 2 | age = 7 3 | 4 | print("I have played the " + instrument + " since I was " + str(age) + " years old.") 5 | -------------------------------------------------------------------------------- /3.5.6 Introduce Yourself, Part 2.py: -------------------------------------------------------------------------------- 1 | #MAKE SURE TO CHANGE YOUR NAME AND AGE! 2 | name = "." 3 | age = 100 4 | print("Hi! My name is " + name + " and I am " + str(age) + " years old.") 5 | -------------------------------------------------------------------------------- /3.5.7 Rectangle, Part 2.py: -------------------------------------------------------------------------------- 1 | length = 10 2 | width = 5 3 | 4 | area = length*width 5 | perimeter = 2*(length+width) 6 | 7 | print("Area: " + str(area)) 8 | print("Perimeter: " + str(perimeter)) 9 | -------------------------------------------------------------------------------- /3.5.8 Rectangle, Part 3.py: -------------------------------------------------------------------------------- 1 | length = int(input("What is the length?: ")) 2 | width = int(input("What is the width?: ")) 3 | 4 | area = length*width 5 | perimeter = 2*(length+width) 6 | 7 | print("Area: " + str(area)) 8 | print("Perimeter: " + str(perimeter)) 9 | -------------------------------------------------------------------------------- /3.5.9 Recipe.py: -------------------------------------------------------------------------------- 1 | user_ingredient1 = input("What should go in a salad?") 2 | user_serving1 = float(input("How many ounces?")) 3 | 4 | user_ingredient2 = input("What else should go in a salad?") 5 | user_serving2 = float(input("How many ounces?")) 6 | 7 | user_ingredient3 = input("What is another thing that should go in a salad?") 8 | user_serving3 = float(input("How many ounces?")) 9 | 10 | serving_count = float(input("How many servings do you want?")) 11 | user_serving1 = user_serving1 * serving_count 12 | user_serving2 = user_serving2 * serving_count 13 | user_serving3 = user_serving3 * serving_count 14 | 15 | user_serving1 = str(user_serving1) 16 | user_serving2 = str(user_serving2) 17 | user_serving3 = str(user_serving3) 18 | 19 | print("Total ounces of", user_ingredient1 + ":", user_serving1) 20 | 21 | print("Total ounces of", user_ingredient2 + ":", user_serving2) 22 | print("Total ounces of",user_ingredient3 + ":", user_serving3) 23 | -------------------------------------------------------------------------------- /3.6.2 Comments: -------------------------------------------------------------------------------- 1 | 1. %% This is a comment 2 | 2. Comments describe your program so other people can read it more easily. 3 | -------------------------------------------------------------------------------- /3.6.5 Add Comments!.py: -------------------------------------------------------------------------------- 1 | """ 2 | different variables for your name 3 | """ 4 | first_name = input("Enter your first name: ") 5 | middle_name = input("Enter your middle name: ") 6 | last_name = input("Enter your last name: ") 7 | 8 | #adds the first + middle + last name together 9 | full_name = first_name + " " + middle_name + " " + last_name 10 | print(full_name) 11 | -------------------------------------------------------------------------------- /3.7.1 Basic Python and Console Interaction Quiz: -------------------------------------------------------------------------------- 1 | 1. 19 2 | 2. 9.5 3 | 3. print(name + ": " + num) 4 | 4. ans = “hi” + 9 5 | 5. 6 | 6. str 7 | 7. 8 | language = "Python" 9 | print("I'm learning " + language) 10 | 8. Numbers that can have decimal components 11 | 9. 12 | 3 13 | 4.4 14 | 10. num = int(input(“Enter a number: “)) 15 | 11. 8 16 | 12. # 17 | 13. A binary operator needs two things, while a unary operator only needs one. 18 | 14. Line 2 19 | 15. A, C, D, B 20 | 16. FlorenceFernandez 21 | 17. I, II, IV 22 | 18. user_age 23 | 19. number 24 | 20. pi = 3.14 25 | -------------------------------------------------------------------------------- /4.1.2 Booleans: -------------------------------------------------------------------------------- 1 | 1. 2 2 | -------------------------------------------------------------------------------- /4.1.4 Fix This Program.py: -------------------------------------------------------------------------------- 1 | brought_food = True 2 | brought_drink = False 3 | brought_food = str(brought_food) 4 | brought_drink = str(brought_drink) 5 | # These lines don't work! Fix them so that they do. 6 | print("Did the person bring food? " + brought_food) 7 | print("Did the person bring a drink? " + brought_drink) 8 | -------------------------------------------------------------------------------- /4.1.5 Plants.py: -------------------------------------------------------------------------------- 1 | needs_water = True 2 | needs_to_be_repotted = False 3 | 4 | print("Needs water: " + str(needs_water)) 5 | print("Needs to be repotted: " + str(needs_to_be_repotted)) 6 | -------------------------------------------------------------------------------- /4.2.2 If Statements: -------------------------------------------------------------------------------- 1 | 1. 2 | if b: 3 | print("b is True!") 4 | 2. 5 | if False: 6 | print("hi") 7 | -------------------------------------------------------------------------------- /4.2.5 Fix This Program.py: -------------------------------------------------------------------------------- 1 | can_juggle = True 2 | 3 | # The code below has problems. See if 4 | # you can fix them! 5 | if can_juggle: 6 | print("I can juggle!") 7 | else: 8 | print("I can't juggle.") 9 | -------------------------------------------------------------------------------- /4.2.6 Is It Raining?.py: -------------------------------------------------------------------------------- 1 | rain = True 2 | 3 | 4 | if rain: 5 | print("I'm going to dance in the rain") 6 | else: 7 | print("I'm going to dance in the sun") 8 | -------------------------------------------------------------------------------- /4.3.10 Transaction.py: -------------------------------------------------------------------------------- 1 | initial_balance = 1000 2 | user_choice = input("Would you like to make a deposit or would you like to withdrawal? Please type deposit for a deposit and withdrawal for a withdrawal: ") 3 | 4 | if user_choice == "withdrawal": 5 | withdraw_amount = int(input("How much money would you like to withdraw?")) 6 | if withdraw_amount >1000: 7 | print("You cannot have a negative balance") 8 | else: 9 | initial_balance = initial_balance - withdraw_amount 10 | print("Final balance:", str(initial_balance)) 11 | elif user_choice == "deposit": 12 | deposit_amount = int(input("How much money would you like to deposit?")) 13 | initial_balance = initial_balance + deposit_amount 14 | print("Final balance:", str(initial_balance)) 15 | else: 16 | print("Invalid transaction") 17 | -------------------------------------------------------------------------------- /4.3.2 Comparison Operators: -------------------------------------------------------------------------------- 1 | 1. False 2 | 2. ? 3 | -------------------------------------------------------------------------------- /4.3.6 Old Enough to Vote?.py: -------------------------------------------------------------------------------- 1 | user_age = int(input("What is your age?")) 2 | requirement_age = 18 3 | 4 | if user_age >= requirement_age: 5 | print("Age:", str(user_age)) 6 | print("You are old enough to vote!") 7 | else: 8 | print("Age:", str(user_age)) 9 | print("You are not old enough to vote.") 10 | -------------------------------------------------------------------------------- /4.3.7 Positive, Zero, or Negative?.py: -------------------------------------------------------------------------------- 1 | user_number = int(input("Enter a number: ")) 2 | 3 | 4 | if user_number > 0: 5 | print("You entered this number:"< str(user_number)) 6 | print("This number is a positive number") 7 | elif user_number < 0: 8 | print("You entered this number:"< str(user_number)) 9 | print("This number is a negative number") 10 | else: 11 | print("You entered this number:"< str(user_number)) 12 | print("This number is zero") 13 | -------------------------------------------------------------------------------- /4.3.9 Table Reservation.py: -------------------------------------------------------------------------------- 1 | user_name = input("Hello, what name is the reservation under? ") 2 | #Change the reservation name from "." to your name (or any name) 3 | reservation_name = "." 4 | 5 | if user_name == reservation_name: 6 | print("Right this way!") 7 | else: 8 | print("Name:", user_name) 9 | print("Sorry, we dont have a reservation under that name.") 10 | -------------------------------------------------------------------------------- /4.4.2 Logical Operators: -------------------------------------------------------------------------------- 1 | 1. because 2 | 2. 3 | if not alarm and tired: 4 | sleep 5 | -------------------------------------------------------------------------------- /4.4.4 Administrators, Teachers, and Students.py: -------------------------------------------------------------------------------- 1 | user_input = input("Are you an administrator, teacher, or student?: ") 2 | if user_input == "teacher" or user_input == "administrator": 3 | print ("Administrators and teachers get keys!") 4 | elif user_input == "student": 5 | print ("Students do not get keys!") 6 | else: 7 | print ("You can only be an administrator, a teacher, or a student!") 8 | -------------------------------------------------------------------------------- /4.4.5 Presidential Eligibility.py: -------------------------------------------------------------------------------- 1 | age = int(input("Age: ")) 2 | if age >= 35: 3 | print ("You are eligible to run for president.") 4 | else: 5 | print ("You are not eligible to run for president.") 6 | -------------------------------------------------------------------------------- /4.4.6 Presidential Eligibility- Extended.py: -------------------------------------------------------------------------------- 1 | age = int(input("Age: ")) 2 | citizen = input("Born in the U.S.? (Yes/No): ") 3 | years_resident = int(input("Years of Residency: ")) 4 | if age >= 35 and citizen == "Yes" and years_resident >= 14: 5 | print ("You are eligible to run for president!") 6 | else: 7 | print ("You are not eligible to run for president.") 8 | if age < 35: 9 | print("You are too young. You must be at least 35 years old.") 10 | if citizen == "No": 11 | print ("You must be born in the U.S. to run for president.") 12 | if years_resident < 14: 13 | print ("You have not been a resident for long enough.") 14 | -------------------------------------------------------------------------------- /4.5.2 Floating Point Numbers and Rounding: -------------------------------------------------------------------------------- 1 | 1. round(x, 2) 2 | 2. 3.000 3 | -------------------------------------------------------------------------------- /4.5.4 Correct Portion.py: -------------------------------------------------------------------------------- 1 | # Amount of food and number of people 2 | tons_of_food = 0.07 3 | num_people = 25 4 | # Determine how much food each person gets 5 | tons_of_food_per_person =round(tons_of_food)/ round(num_people) 6 | print(tons_of_food_per_person) 7 | # Ask the user how much food they took 8 | tons_taken = float(input("How many tons of food did you take? ")) 9 | if round(tons_taken, 5) == round(tons_of_food_per_person, 5): 10 | print ("Good job, you took the right amount of food!") 11 | else: 12 | print ("You took the wrong amount of food!") 13 | -------------------------------------------------------------------------------- /4.6.1 Conditionals Quiz: -------------------------------------------------------------------------------- 1 | 1. Must be blue 2 | 2. round(pi, 2) 3 | 3. Sometimes numbers can be rounded in unexpected ways based on how Python computes them. Therefore, it is best to use round in order to make sure both numbers are rounded the same way. 4 | 4. 5 | 5. 6 | 6. 5 7 | 7. Nothing will print 8 | 8. -5 9 | 9. 10 | 5 11 | 8 12 | 10. Almost eligible for Driver’s License 13 | 11. 14 | 1 15 | 4 16 | 5 17 | 12. 1 18 | 13. You are average height 19 | 14. You are above average height 20 | 15. 21 | But green is the color of grass! 22 | Blue is the best 23 | But yellow is the color of school buses! 24 | -------------------------------------------------------------------------------- /5.1.2 While Loops: -------------------------------------------------------------------------------- 1 | 1. an infinite number of lines 2 | 2. 4 3 | -------------------------------------------------------------------------------- /5.1.6 2 Through 20 Even.py: -------------------------------------------------------------------------------- 1 | number = 0 2 | 3 | while(number < 20): 4 | number = number + 2 5 | print(number) 6 | -------------------------------------------------------------------------------- /5.1.7 Divisibility.py: -------------------------------------------------------------------------------- 1 | number= 3 2 | numerator = int(input("Enter a numerator: ")) 3 | denominator = int(input("Enter denominator: ")) 4 | # Use a while loop here to repeatedly ask the user for 5 | # a denominator for as long as the denominator is 0 6 | # (or, put another way, until the denominator is not 7 | # equal to 0). 8 | if int(numerator / denominator) * denominator == numerator: 9 | print("Divides evenly!") 10 | else: 11 | print("Doesn't divide evenly.") 12 | while number >3: 13 | print("code complete") 14 | -------------------------------------------------------------------------------- /5.2.2 For Loops: -------------------------------------------------------------------------------- 1 | 1. for i in range(10): 2 | print("hi") 3 | 2. A for loop is for doing something a fixed number of times. -------------------------------------------------------------------------------- /5.2.5 Counting 10 to 100 by Tens.py: -------------------------------------------------------------------------------- 1 | for i in range(1, 11): 2 | print (i * 10) 3 | -------------------------------------------------------------------------------- /5.2.8 Average Test Score.py: -------------------------------------------------------------------------------- 1 | LOOP = 3 2 | total = 0 3 | 4 | for i in range(LOOP): 5 | user_input = float(input(str(i + 1) + ". Please enter your test score: ")) 6 | total = total + user_input 7 | 8 | total = total / LOOP 9 | print ("Average score: " + str(total)) 10 | -------------------------------------------------------------------------------- /5.2.9 How Many Names?.py: -------------------------------------------------------------------------------- 1 | names = int(input("How many names do you have? ")) 2 | name = "" 3 | full_name = "" 4 | 5 | for i in range(names): 6 | name = input(str(i + 1) + "Please enter your name: ") 7 | full_name = full_name + " " + name 8 | 9 | print("Your full name is:" + full_name) 10 | -------------------------------------------------------------------------------- /5.3.2 Break and Continue: -------------------------------------------------------------------------------- 1 | 1. break 2 | 2. continue -------------------------------------------------------------------------------- /5.3.7 Higher or Lower.py: -------------------------------------------------------------------------------- 1 | magic_number = 3 2 | guess = 0 3 | 4 | while(magic_number != guess): 5 | guess = int(input("Enter a number: ")) 6 | if(guess < magic_number): 7 | print("Too low!") 8 | elif(guess > magic_number): 9 | print("Too high!") 10 | else: 11 | print("Correct!") 12 | break; 13 | -------------------------------------------------------------------------------- /5.4.2 Nested Control Structures: -------------------------------------------------------------------------------- 1 | 1. 2 | 0 3 | 1 4 | 1 5 | 2 6 | 2. 7 | count = 10 8 | for i in range(3): 9 | if count > 0: 10 | print(i) 11 | else: 12 | print(count) 13 | -------------------------------------------------------------------------------- /5.4.6 Rolling Dice.py: -------------------------------------------------------------------------------- 1 | for i in range(6): 2 | for j in range(6): 3 | print(str(i+1)+","+str(j+1)) 4 | -------------------------------------------------------------------------------- /5.4.7 Categories.py: -------------------------------------------------------------------------------- 1 | for i in range(3): 2 | cat = input("Enter a catagory: ") 3 | items = [] 4 | for j in range(3): 5 | items.append(input("Enter something in that catagory: ")) 6 | print(cat + ": " + " ".join(items)) 7 | -------------------------------------------------------------------------------- /5.5.1 Looping Unit Test: -------------------------------------------------------------------------------- 1 | 1. 2 | for i in range(6): 3 | print(i) 4 | 2. 5 | for i in range(3, 10, 2): 6 | print(i) 7 | 3. 12 8 | 4. for i in range(0, 10): 9 | 5. for i in range(5, 0, 1): 10 | 6. 11 | It’s still a nice day 12 | It’s still a nice day 13 | It’s still a nice day 14 | It’s still a nice day 15 | 7. 16 | while num < 12 and num > 3: 17 | # do something with num 18 | 8. 19 | secret_num = 10 20 | 21 | while secret_num == 10: 22 | print(secret_num) 23 | 9. When you don’t know how many times something will need to repeat 24 | 10. 25 | 0 26 | 1 27 | 0 28 | 1 29 | 11. 9 30 | 12. -150 31 | 13. 32 | 0 33 | 1 34 | 2 35 | 4 36 | 5 37 | 6 38 | 7 39 | 8 40 | 9 41 | 14. The program will break out of the loop as soon as the user enters the magic_number 42 | 15. On linw 9 43 | -------------------------------------------------------------------------------- /6.1.2 Functions: -------------------------------------------------------------------------------- 1 | 1. 2 | def print_hello(): 3 | print("hello") 4 | 2. 5 | print_sum() 6 | -------------------------------------------------------------------------------- /6.1.5 Weather.py: -------------------------------------------------------------------------------- 1 | user_weather = input("What is the weather? (sunny, rainy, snowy):") 2 | 3 | # Case sensitive 4 | def rainy(): 5 | print("On a rainy day, galoshes are appropriate footwear.") 6 | def sunny(): 7 | print("Put on some sandals!!!!!!!!!!!!!!") 8 | def snowy(): 9 | print("Put on some boots!!!!!!!!!!!!!!!") 10 | 11 | if user_weather == "rainy": 12 | rainy() 13 | elif user_weather == "sunny": 14 | sunny() 15 | elif user_weather == "snowy": 16 | snowy() 17 | else: 18 | print("Not valid") 19 | -------------------------------------------------------------------------------- /6.2.2 Functions and Parameters: -------------------------------------------------------------------------------- 1 | 1. print_number(10) 2 | 2. 3 | def print_number(x): 4 | print(x) 5 | -------------------------------------------------------------------------------- /6.2.5 Print Product.py: -------------------------------------------------------------------------------- 1 | def printintegers(x, y): 2 | print (x,y) 3 | 4 | printintegers(1, 2) 5 | -------------------------------------------------------------------------------- /6.2.6 Print Multiple Times.py: -------------------------------------------------------------------------------- 1 | def printmultiple(string, number): 2 | for i in range(number): 3 | print(string) 4 | 5 | printmultiple("ahhhh", 3) 6 | -------------------------------------------------------------------------------- /6.2.8 Area of a Square with Default Parameters.py: -------------------------------------------------------------------------------- 1 | side_length = 10 2 | def calculate_area(side_length=10): 3 | side_length = int(input("Enter side length: ")) 4 | if side_length <= 0: 5 | side_length = 10 6 | print("The area of a square with sides of length " + str(side_length) + " is " + str(side_length**2) + ".") 7 | 8 | calculate_area(side_length) 9 | -------------------------------------------------------------------------------- /6.3.2 Namespaces in Functions: -------------------------------------------------------------------------------- 1 | 1. Global namespace 2 | 2. 3 | def subtract_nums(): 4 | y = 5 5 | z = x - y 6 | print(z) 7 | -------------------------------------------------------------------------------- /6.3.5 Fix This Program!.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program takes two values and prints their total. 3 | """ 4 | 5 | def add_nums(num1, num2): 6 | total = num1 + num2 7 | 8 | total=add_nums(5, 6) 9 | print(total) 10 | -------------------------------------------------------------------------------- /6.3.6 Adding to a Value.py: -------------------------------------------------------------------------------- 1 | num1 = 10 2 | # Your code here... 3 | num2 = int(input("Number:")) 4 | def addnum(): 5 | sum = num1 + num2 6 | print(sum) 7 | 8 | addnum() 9 | -------------------------------------------------------------------------------- /6.3.7 Add, Subtract, or Multiply.py: -------------------------------------------------------------------------------- 1 | num1 = int(input("What is the first number?:")) 2 | num2 = int(input("What is the second number?:")) 3 | mathtype = input("Choose an operation (add, subtract, multiply):") 4 | 5 | def do_math(): 6 | sum = num1 + num2 7 | print (str(num1) + " + " + str(num2) + " = " + str(sum)) 8 | def do_math_subtract(): 9 | sum = num1 - num2 10 | print (str(num1) + " - " + str(num2) + " = " + str(sum)) 11 | def do_math_multiply(): 12 | sum = num1 * num2 13 | print (str(num1) + " * " + str(num2) + " = " + str(sum)) 14 | 15 | if mathtype == "add": 16 | do_math() 17 | elif mathtype == "subtract": 18 | do_math_subtract() 19 | elif mathtype == "multiply": 20 | do_math_multiply() 21 | -------------------------------------------------------------------------------- /6.4.2 Functions and Return Values: -------------------------------------------------------------------------------- 1 | 1. def my_function(number): 2 | return number*2 3 | 2. 4 | def my_function(): 5 | return 10 6 | -------------------------------------------------------------------------------- /6.4.8 Sum Two Numbers.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | y = 6 3 | def sum_two_numbers(x, y): 4 | return x + y 5 | print(return) 6 | sum_two_numbers(x,y) 7 | -------------------------------------------------------------------------------- /6.4.9 Temperature Converter.py: -------------------------------------------------------------------------------- 1 | # Write your function for converting Celsius to Fahrenheit here. 2 | # Make sure to include a comment at the top that says what 3 | # each function does! 4 | 5 | def to_F(c): 6 | return float(1.8 * c + 32) 7 | 8 | # Now write your function for converting Fahrenheit to Celsius. 9 | def to_C(f): 10 | return float((f - 32) / 1.8) 11 | 12 | # Now change 0C to F: 13 | print (to_F(0)) 14 | 15 | # Now change 100C to F: 16 | print (to_F(100)) 17 | 18 | # Now change 40C to F: 19 | print (to_C(40)) 20 | 21 | # Now change 80C to F: 22 | print (to_C(80)) 23 | -------------------------------------------------------------------------------- /6.5.2 Exceptions: -------------------------------------------------------------------------------- 1 | 1. II and III 2 | 2. ValueError 3 | -------------------------------------------------------------------------------- /6.5.5 Temperature Converter, Part 2.py: -------------------------------------------------------------------------------- 1 | def celsius_to_fahrenheit(c): 2 | return float (1.8 * c + 32) 3 | def fahrenheit_to_celsius(f): 4 | return float ((f-32) / 1.8) 5 | try: 6 | user_number = float(input("Give a temperature in celsius:")) print (celsius_to_fahrenheit(user_number)) user_number = float(input("Give a temperature in fahrenheit:")) print (fahrenheit_to_celsius(user_number)) 7 | except ValueError: 8 | print ("Not valid.") 9 | -------------------------------------------------------------------------------- /6.5.6 Enter a Positive Number.py: -------------------------------------------------------------------------------- 1 | def retrieve_positive_number(): 2 | while True: 3 | try: 4 | num = int(input("Enter a positive number: ")) 5 | if num > 0: 6 | return num 7 | print("The number must be positive!") 8 | except ValueError: 9 | print("That wasn't a number!") 10 | 11 | # Call the function and print 12 | print retrieve_positive_number() 13 | -------------------------------------------------------------------------------- /6.6.1 Functions and Exceptions Quiz: -------------------------------------------------------------------------------- 1 | 1. 2 | def say_hi(first_name="John", last_name="Doe"): 3 | print("hi " + first_name + " " + last_name) 4 | 5 | say_hi("Polly Pocket") 6 | 2. 7 | def balloon_choice(color): 8 | print("I would like a " + color + " balloon.") 9 | 10 | balloon_choice("green") 11 | 3. codecodecode 12 | 4. hello Turtle 13 | 5. <><><> 14 | 6. 15 | for i in range(6): 16 | fn_a(i) 17 | 7. 18 | Original Point: 12, 14 19 | Midpoint from Origin: 6.0, 7.0 20 | Point: 16, 20 21 | 8. 22 | # computes the surface area of a rectangular prism 23 | def surface_area(length, width=10, height): 24 | return 2*(length * width + width * height + height * length) 25 | 9. 26 | Welcome to CodeHS! 27 | Enter your username: kipp52 28 | That's not a valid username. Try again 29 | Enter your username: baseball45 30 | Welcome! 31 | 10. 50 32 | 11. To indicate that something has gone wrong, and the program does not know how to continue 33 | 12. 34 | Enter a positive number: 1.2 35 | That wasn't a number! 36 | Enter a positive number: -4 37 | The number must be positive! 38 | Enter a positive number: hi 39 | That wasn't a number! 40 | Enter a positive number: 5 41 | 5 42 | 13. 5 43 | 14. print(get_single_digit() + get_single_digit()) 44 | 15. To handle exceptions gracefully and either handle the error or print out a useful error message. 45 | -------------------------------------------------------------------------------- /7.1.2 Indexing: -------------------------------------------------------------------------------- 1 | 1. 2 | my_string = "ABCDE" 3 | print(my_string[0]) 4 | 2. 5 | my_string = "ABCDE" 6 | print(my_string[-1]) 7 | -------------------------------------------------------------------------------- /7.1.5 Initials.py: -------------------------------------------------------------------------------- 1 | # fill in the body of this function! 2 | first = "" 3 | last = "" 4 | def initials(first, last): 5 | return (first[0] + "." + last[0] + ".") 6 | 7 | print (initials(first,last)) 8 | -------------------------------------------------------------------------------- /7.1.6 Sandwich Sandwiches.py: -------------------------------------------------------------------------------- 1 | # update the function's body to return the 2 | # first and last letter of the input concatenated together 3 | string = "pbj" 4 | def sandwich(string): 5 | return (string[0] + "" + string[-1]) 6 | 7 | print (sandwich(string)) 8 | -------------------------------------------------------------------------------- /7.2.2 Slicing: -------------------------------------------------------------------------------- 1 | 1. + 2 | 2. print(sign[:6] + "Birth" + sign[6:]) 3 | 3. 4 | my_string = "ABCDE" 5 | print(my_string[2:]) 6 | -------------------------------------------------------------------------------- /7.2.6 If You're Not First, You're Last.py: -------------------------------------------------------------------------------- 1 | # update the function body to return everything but the first letter 2 | word = "Surron" 3 | def end_of_word(word): 4 | return (word[1:]) 5 | 6 | print (end_of_word(word)) 7 | -------------------------------------------------------------------------------- /7.2.7 Part 1, Replace a Letter.py: -------------------------------------------------------------------------------- 1 | string = "eggplant" 2 | index = 3 3 | letter = "-" 4 | 5 | def replace_at_index(string, index): 6 | return string[:index] + letter + string[index+1:] 7 | 8 | print (replace_at_index(string,index)) 9 | -------------------------------------------------------------------------------- /7.2.8 Part 2, Replace a Letter.py: -------------------------------------------------------------------------------- 1 | string = "house" 2 | index = 3 3 | string2 = "e" 4 | 5 | def replace_at_index(string, index, string2): 6 | return string[:index] + string2 + string[index+1:] 7 | 8 | print (replace_at_index(string,index, string2)) 9 | -------------------------------------------------------------------------------- /7.3.2 Immutability: -------------------------------------------------------------------------------- 1 | 1. immutable 2 | 2. Strings in Python can be replaced, but not modified. 3 | -------------------------------------------------------------------------------- /7.3.4 Find the Error.py: -------------------------------------------------------------------------------- 1 | my_string = "hello!" 2 | 3 | # One of the two lines below will cause an error. 4 | # Each line is an attempt to replace the first 5 | # letter of myString with H. Comment out the 6 | # line you think is incorrect. 7 | def bad(): 8 | 9 | my_string[0] = "H" 10 | 11 | my_string = "H" + my_string[1:] 12 | 13 | print(my_string) 14 | -------------------------------------------------------------------------------- /7.4.2 Strings and For Loops: -------------------------------------------------------------------------------- 1 | 1. 2 | my_string = "abcde" 3 | for letter in range(len(my_string)): 4 | print(letter) 5 | 2. 5 6 | -------------------------------------------------------------------------------- /7.4.4 Length of User's Name.py: -------------------------------------------------------------------------------- 1 | name = "" 2 | def name_length(name): 3 | return len(name) 4 | print (name_length(name)) 5 | -------------------------------------------------------------------------------- /7.4.7 Spelling Bee.py: -------------------------------------------------------------------------------- 1 | word = "eggplant" 2 | 3 | # Give the word to spell 4 | print("Your word is: " + word + ".") 5 | 6 | # Spell the word with a for loop here! 7 | 8 | 9 | def spell_word(): 10 | for letter in word: 11 | print(letter + "!") 12 | 13 | 14 | spell_word() 15 | -------------------------------------------------------------------------------- /7.4.8 Keeping Count.py: -------------------------------------------------------------------------------- 1 | # update this function to return the number of times `second` appears in `first`! 2 | def count_occurrences(e, d): 3 | counter = 0 4 | for checker in e: 5 | if (checker == d): 6 | counter= counter + 1 7 | return counter 8 | print (count_occurrences("elephant", "e")) 9 | -------------------------------------------------------------------------------- /7.5.2 The in Keyword: -------------------------------------------------------------------------------- 1 | 1. True 2 | 2. False 3 | -------------------------------------------------------------------------------- /7.5.5 Contains a Vowel.py: -------------------------------------------------------------------------------- 1 | word = "abcdefghijklmnopqrstuvwxyz" 2 | def contains_vowel(word): 3 | vowels = ["a", "e", "i","o", "u"] 4 | for vowel in vowels: 5 | if vowel in word: 6 | return True 7 | return False 8 | print (contains_vowel(word)) 9 | -------------------------------------------------------------------------------- /7.6.10 Part 2, Remove All From String.py: -------------------------------------------------------------------------------- 1 | word = "bananas" 2 | letter = "na" 3 | 4 | def remove_all_from_string(word, letter): 5 | while True: 6 | index = word.find(letter) 7 | if index == -1: 8 | return word 9 | word = word[:index] + word[index+len(letter):] 10 | 11 | print (remove_all_from_string(word, letter)) 12 | -------------------------------------------------------------------------------- /7.6.2 String Methods: -------------------------------------------------------------------------------- 1 | 1. 2 | s = "apple" 3 | x = s.find("l") 4 | print(x) 5 | 2. lower 6 | -------------------------------------------------------------------------------- /7.6.4 ENTHUSIASM!.py: -------------------------------------------------------------------------------- 1 | string = "codehs rocks" 2 | def add_enthusiasm(string): 3 | string = string.upper() 4 | return string + "!" 5 | 6 | print (add_enthusiasm(string)) 7 | -------------------------------------------------------------------------------- /7.6.8 What's in a Name?.py: -------------------------------------------------------------------------------- 1 | name = "" 2 | letter = "e" 3 | def name_contains(name, letter): 4 | name.find(letter) 5 | if name.find(letter) !=-1: 6 | return True 7 | else: 8 | return False 9 | 10 | print (name_contains(name, letter)) 11 | -------------------------------------------------------------------------------- /7.6.9 Part 1, Remove All From String.py: -------------------------------------------------------------------------------- 1 | def remove_all_from_string(word, letter): 2 | return word.replace(letter, '') 3 | -------------------------------------------------------------------------------- /7.7.1 Strings Quiz: -------------------------------------------------------------------------------- 1 | 1. print(sentence[4:9]) 2 | 2. print(sentence[5:]) 3 | 3. print(word[-2]) 4 | 4. word[0] = "M" 5 | 5. II, IV 6 | 6. 7 | tt 8 | hh 9 | ee 10 | 11 | dd 12 | oo 13 | gg 14 | 7. 15 | if "the" in sentence: 16 | print("Contains 'the'") 17 | 8. 18 | def alt_case(word): 19 | res = "" 20 | for i in range(len(word)): 21 | if i % 2 == 1: 22 | res = res + word[i].upper() 23 | else: 24 | res = res + word[i].lower() 25 | return res 26 | 9. 7 27 | 10. 0 28 | 11. -1 29 | 12. Returns the same sentence, but replaces every space with the letter char 30 | 13. Checks to make sure the email address is valid by checking for ‘@’ in the address. Returns the address without any leading or trailing whitespace. 31 | 14. Line 4 32 | 15. The variable can be assigned a new value, but the string’s value cannot be modified. 33 | 16. killer whale 34 | 17. azbycxdwev 35 | 18. 36 | def find_secret_word(message): 37 | hidden_word = "" 38 | for letter in message: 39 | if letter != letter.lower(): 40 | hidden_word = hidden_word + letter 41 | return hidden_word 42 | 19. upper 43 | 20.print(first_name[0] + first_name[-1] + last_name[0] + last_name[-1]) 44 | -------------------------------------------------------------------------------- /8.1.10 Coordinate Pairs.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | # fill in this function to return the distance between the two points! 4 | 5 | first_point = (1, 1) 6 | second_point = (4, 5) 7 | def distance(first_point, second_point): 8 | #Establishes the value of X and Y 9 | x1= first_point[0] 10 | x2= second_point[0] 11 | y1= first_point[1] 12 | y2= second_point[1] 13 | # math 14 | power1 = pow(y2 - y1, 2) 15 | power2 = pow(x2 - x1, 2) 16 | return math.sqrt (power1 + power2) 17 | print (distance(first_point, second_point)) 18 | -------------------------------------------------------------------------------- /8.1.2 Tuples: -------------------------------------------------------------------------------- 1 | 1. Tuples use parentheses to access individual elements, rather than square brackets. 2 | 2. x = (1, 2, 3) 3 | -------------------------------------------------------------------------------- /8.1.7 Fix This Tuple.py: -------------------------------------------------------------------------------- 1 | my_tuple = (0, 1, 2, "hi", 4, 5) 2 | 3 | print(my_tuple[:3] + (3,) + my_tuple[4:]) 4 | -------------------------------------------------------------------------------- /8.1.8 Citation.py: -------------------------------------------------------------------------------- 1 | # fill in the `citation` function to return the author's name in the correct format 2 | def citation (a): 3 | first, middle, last = a 4 | return f"{last}, {first} {middle}" 5 | 6 | print(citation(("Martin", "Luther", "King, Jr."))) 7 | -------------------------------------------------------------------------------- /8.1.9 Diving Contest.py: -------------------------------------------------------------------------------- 1 | # fill in this function to return the total of the three judges' scores! 2 | judges_scores=(10,10,10) 3 | def calculate_score(judges_scores): 4 | return judges_scores[0]+judges_scores[1]+judges_scores[2] 5 | print (calculate_score(judges_scores)) 6 | -------------------------------------------------------------------------------- /8.2.2 Lists: -------------------------------------------------------------------------------- 1 | 1. my_list = [1, 2, 3, 4, 5] 2 | 2. 3 | my_string = "hello" 4 | str_as_list = list(my_string) 5 | -------------------------------------------------------------------------------- /8.2.5 Spell It Out.py: -------------------------------------------------------------------------------- 1 | name = "" 2 | 3 | def spell_name(name): 4 | spell_out = list(name) 5 | return spell_out 6 | 7 | print (spell_name(name)) 8 | -------------------------------------------------------------------------------- /8.2.7 Listed Greeting.py: -------------------------------------------------------------------------------- 1 | # fill in this function to greet the user! 2 | #Format: 3 | #Example: Aditeya 14 coding 4 | user_info = "Info here" 5 | 6 | def greeting(user_info): 7 | greeting = user_info.split() 8 | return "Hello, " + (greeting[0]) + "! I also enjoy " + (greeting[-1]) + "!" 9 | 10 | print (greeting(user_info)) 11 | -------------------------------------------------------------------------------- /8.3.5 Max In List.py: -------------------------------------------------------------------------------- 1 | #the function should return the maximum value in `my_list` 2 | my_list = [1, 3, 456, 2038] 3 | def max_int_in_list(my_list): 4 | highest = my_list[-1] 5 | for num in my_list: 6 | if num > highest: 7 | highest = num 8 | return highest 9 | 10 | biggest_int = max_int_in_list(my_list) 11 | 12 | print (biggest_int) 13 | -------------------------------------------------------------------------------- /8.3.6 Owls.py: -------------------------------------------------------------------------------- 1 | # this function should return the number of words that contain "owl"! 2 | text ="I really like owls. Did you know that an owl's eyes are more than twice as big as the eyes of other birds of comparable weight? And that when an owl partially closes its eyes during the day, it is just blocking out light? Sometimes I wish I could be an owl." 3 | 4 | word ="owl" 5 | def owl_count(text): 6 | text=text.lower() 7 | owlist=list(text.split()) 8 | count=text.count(word) 9 | return count 10 | 11 | print (owl_count(text)) 12 | -------------------------------------------------------------------------------- /8.3.7 Exclamat!on Po!nts.py: -------------------------------------------------------------------------------- 1 | def exclamation(myStr): 2 | s = list(myStr) 3 | for i in range(len(s)): 4 | if s[i] == "i": 5 | s[i] = '!' 6 | myStr = "".join(s) 7 | return myStr 8 | -------------------------------------------------------------------------------- /8.3.8 Word Ladder.py: -------------------------------------------------------------------------------- 1 | user_string = input("Enter a string: ") 2 | 3 | def get_index(): 4 | while True: 5 | try: 6 | user_index = int(input("Enter an Index: ")) 7 | if user_index >= len(user_string): 8 | print("Invalid Index") 9 | continue 10 | if user_index < -1: 11 | print("Invalid Index") 12 | continue 13 | except ValueError: 14 | print("Invalid Index") 15 | continue 16 | return user_index 17 | 18 | def get_string(): 19 | while True: 20 | user_letter = input("Enter letter: ") 21 | if user_letter.isupper(): 22 | print("Character must be a lowercase letter!") 23 | continue 24 | if len(user_letter) > 1: 25 | print("Must be exactly one character!") 26 | continue 27 | return user_letter 28 | 29 | 30 | while True: 31 | user_string = list(user_string) 32 | returned_index = get_index() 33 | if returned_index == -1: 34 | break 35 | returned_string = get_string() 36 | user_string[returned_index] = returned_string 37 | print("".join(user_string)) 38 | -------------------------------------------------------------------------------- /8.3.9 Owls, Part 2.py: -------------------------------------------------------------------------------- 1 | def owl_count(): 2 | count = 0 3 | report = [] 4 | text = input("Enter a Sentence: ") 5 | text= text.lower() 6 | for index, word in enumerate(text.split()): 7 | if word.find("owl") > -1: 8 | count += 1 9 | report += [index,] 10 | print("They were " + str(count) + """ words that contained "owl".""") 11 | print("They occurred at indices: " + str(report)) 12 | 13 | owl_count() 14 | -------------------------------------------------------------------------------- /8.4.11 Take a Thing Out, Sort It and Reverse It.py: -------------------------------------------------------------------------------- 1 | my_list=["eggplant", "apple", "zucchini", "rambutan", "grapefruit"] 2 | 3 | def remove_sort_reverse(my_list): 4 | # perform operations on `my_list` to 5 | # 1. remove all "eggplant"s 6 | my_list.remove("eggplant") 7 | # 2. sort it 8 | my_list.sort() 9 | # 3. reverse it! 10 | my_list.reverse() 11 | return my_list 12 | 13 | print(remove_sort_reverse(my_list)) 14 | -------------------------------------------------------------------------------- /8.4.12 Librarian, Part 2.py: -------------------------------------------------------------------------------- 1 | list=[] 2 | 3 | for i in range (5): 4 | name = input("Name: ") 5 | list.append(name.split()[-1]) 6 | 7 | list.sort() 8 | print(list) 9 | -------------------------------------------------------------------------------- /8.4.2 List Methods: -------------------------------------------------------------------------------- 1 | 1. my_list.sort() 2 | 2. 3 | my_list.sort() 4 | my_list.reverse() 5 | my_list.remove("bananas") 6 | -------------------------------------------------------------------------------- /8.4.4 How Many Names?.py: -------------------------------------------------------------------------------- 1 | nn = int(input("How many names do you have?:")) 2 | namelist = [] 3 | for i in range (nn): 4 | name = input("Name:") 5 | namelist.append(name) 6 | 7 | print ("First name:" + namelist[0]) 8 | print ("Middle names:" + str(namelist[1:-1])) 9 | print ("Last name:" + namelist[-1]) 10 | -------------------------------------------------------------------------------- /8.4.5 Five Numbers.py: -------------------------------------------------------------------------------- 1 | list=[] 2 | 3 | for i in range(5): 4 | number=int(input("Number:")) 5 | list.append(number) 6 | print(list) 7 | 8 | final=sum(list) 9 | print(final) 10 | -------------------------------------------------------------------------------- /8.4.7 Librarian.py: -------------------------------------------------------------------------------- 1 | list=[] 2 | 3 | for i in range(5): 4 | name=input("Name:") 5 | list.append(name) 6 | list.sort() 7 | print(list) 8 | -------------------------------------------------------------------------------- /8.5.1 Creating and Altering Data Structures Quiz: -------------------------------------------------------------------------------- 1 | 1. Tuple 2 | 2. [48, 56, 64, 65, 60, 61, 62] 3 | 3. 4 4 | 4. 5 | B 6 | o 7 | n 8 | d 9 | 0 10 | 0 11 | 7 12 | 5. 13 | for index in range(len(my_list)): 14 | if index % 2 == 0: 15 | print(my_list[index]) 16 | 6. 5, -10, 6 17 | 7. 18 | my_list = ["honey", "bread", "jelly", "plates"] 19 | 20 | for index in range(len(my_list)): 21 | print(str(index+1) + ". " + my_list[index]) 22 | 8. 23 | my_list = ['red', 'green', 'blue', 'orange'] 24 | 25 | my_list.append('yellow') 26 | 9. [1, 2, 3, 4, 5, 6, 7, 8] 27 | 10. Tuple 28 | 11. List 29 | 12. ages[0] = 3 30 | 13. banan 31 | 14. 5 32 | 15. My favorite animal is a penguin or chipmunk 33 | -------------------------------------------------------------------------------- /9.1.2 2d Lists: -------------------------------------------------------------------------------- 1 | 1. [2, 5, 7, 10] 2 | 2. [[2, 5, 7, 10], [-3, ‘hello’, 9, ‘hi’]] 3 | -------------------------------------------------------------------------------- /9.1.6 Checkerboard, v1.py: -------------------------------------------------------------------------------- 1 | # Pass this function a list of lists, and it will 2 | # print it such that it looks like the grids in 3 | # the exercise instructions. 4 | def print_board(board): 5 | for i in range(len(board)): 6 | 7 | # This line uses some Python you haven't 8 | # learned yet. You'll learn about this 9 | # part in a future lesson 10 | # 11 | # [str(x) for x in board[i]] 12 | print(" ".join([str(x) for x in board[i]])) 13 | 14 | board=[] 15 | 16 | for i in range(3): 17 | board.append([1]*8) 18 | for i in range(2): 19 | board.append([0]*8) 20 | for i in range(3): 21 | board.append([1]*8) 22 | board[2][1] = 1 23 | 24 | print_board(board) 25 | -------------------------------------------------------------------------------- /9.1.7 Checkerboard, v2.py: -------------------------------------------------------------------------------- 1 | # Pass this function a list of lists, and it will 2 | # print it such that it looks like the grids in 3 | # the exercise instructions. 4 | def print_board(board): 5 | for i in range(len(board)): 6 | 7 | # This line uses some Python you haven't 8 | # learned yet. You'll learn about this 9 | # part in a future lesson 10 | # 11 | # [str(x) for x in board[i]] 12 | print(" ".join([str(x) for x in board[i]])) 13 | 14 | my_grid = [] 15 | for i in range(8): 16 | my_grid.append([0]*8) 17 | 18 | for i in range(8): 19 | for x in range(8): 20 | if(i+x)%2==1: 21 | my_grid[i][x]=1 22 | print_board(my_grid) 23 | -------------------------------------------------------------------------------- /9.1.8 Checkerboard, v3.py: -------------------------------------------------------------------------------- 1 | # Pass this function a list of lists, and it will 2 | # print it such that it looks like the grids in 3 | # the exercise instructions. 4 | def print_board(board): 5 | for i in range(len(board)): 6 | 7 | # This line uses some Python you haven't 8 | # learned yet. You'll learn about this 9 | # part in a future lesson 10 | # 11 | # [str(x) for x in board[i]] 12 | print(" ".join([str(x) for x in board[i]])) 13 | 14 | my_grid = [] 15 | for i in range(8): 16 | my_grid.append([0] * 8) 17 | for row in range(8): 18 | for col in range(8): 19 | if (row + col) % 2 == 1 and (row < 3 or row > 4): 20 | my_grid[row][col] = 1 21 | print_board(my_grid) 22 | -------------------------------------------------------------------------------- /9.1.9 Tic Tac Toe.py: -------------------------------------------------------------------------------- 1 | """ 2 | This program simulates the game of tic tac toe. 3 | """ 4 | 5 | # get_valid_index 6 | # ----- 7 | # Get row or column from user 8 | def get_valid_index(prompt): 9 | while True: 10 | try: 11 | index = int(input(prompt)) 12 | if index >= 0 and index <= 2: 13 | return index 14 | print("Must be 0 - 2 inclusive!") 15 | except ValueError: 16 | print("Must be an integer!") 17 | 18 | # game_is_over 19 | # ----- 20 | # Return True if the game is over and False 21 | # otherwise. Print a message indicating who 22 | # won or whether there was a tie. 23 | def game_is_over(board): 24 | for i in range(3): 25 | # Check horizontal 26 | if board[i][0] == board[i][1] == board[i][2] \ 27 | and board[i][0] != " ": 28 | print(board[i][0] + " wins!") 29 | return True 30 | 31 | # Check vertical 32 | if board[0][i] == board[1][i] == board[2][i] \ 33 | and board[0][i] != " ": 34 | print(board[0][i] + " wins!") 35 | return True 36 | 37 | # Check diagonals 38 | if board[0][0] == board[1][1] == board[2][2] \ 39 | and board[0][0] != " ": 40 | print(board[0][0] + " wins!") 41 | return True 42 | 43 | if board[2][0] == board[1][1] == board[0][2] \ 44 | and board[2][0] != " ": 45 | print(board[2][0] + " wins!") 46 | return True 47 | 48 | # Check tie 49 | if " " not in board[0] and " " not in board[1] \ 50 | and " " not in board[2]: 51 | print("Tie game!") 52 | return True 53 | 54 | # Not over yet! 55 | return False 56 | 57 | # print_board 58 | # ----- 59 | # Print the board. 60 | def print_board(board): 61 | # TODO: Replace the line below with your code... 62 | for i in range(3): 63 | print(board[i]) 64 | 65 | # Set up board 66 | board = [] 67 | # TODO: Set up the board as a 3x3 grid of spaces here... 68 | board = [[' ', ' ', ' '], 69 | [' ', ' ', ' '], 70 | [' ', ' ', ' ']] 71 | # x goes first 72 | turn = "x" 73 | 74 | # Play tic tac toe 75 | while not game_is_over(board): 76 | print_board(board) 77 | print("It's " + turn + "'s turn.") 78 | row = get_valid_index("Row: ") 79 | col = get_valid_index("Col: ") 80 | # TODO: Your code here... 81 | if board[row][col] == ' ': 82 | board[row][col] = turn 83 | else: 84 | print("Choose a different spot") 85 | continue 86 | if turn == 'x': 87 | turn = 'o' 88 | else: 89 | turn = 'x' 90 | -------------------------------------------------------------------------------- /9.2.2 List Comprehensions: -------------------------------------------------------------------------------- 1 | 1. [0, 2, 4, 6] 2 | 2. [True, False, True, False, True, False] 3 | -------------------------------------------------------------------------------- /9.2.5 Divisible by 3.py: -------------------------------------------------------------------------------- 1 | numbers = [ x % 3 == 0 for x in range(1, 11) ] 2 | 3 | print(numbers) 4 | -------------------------------------------------------------------------------- /9.2.8 Last Names.py: -------------------------------------------------------------------------------- 1 | names_list = ["Angelou", "Adichie", "Wolff", "Alexie", "Ansari"] 2 | for i in range(0, 5): 3 | sorted_last_names = [name.split()[-1] for name in names_list] 4 | print(sorted_last_names) 5 | -------------------------------------------------------------------------------- /9.2.9 Strings To Integers.py: -------------------------------------------------------------------------------- 1 | def safe_int(string): 2 | return int(string) if string.isdigit() else 0 3 | 4 | list_of_strings = ["a", "2", "7", "zebra"] 5 | list_of_numbers = [safe_int(num) for num in list_of_strings] # <-- use the function INSIDE the list comprehension 6 | print(list_of_numbers) 7 | 8 | list_of_strings = ["a", "2", "7", "zebra"] 9 | -------------------------------------------------------------------------------- /9.3.2 Packing and Unpacking: -------------------------------------------------------------------------------- 1 | 1. 2 | x = 1 3 | y = 2 4 | z = 3 5 | my_list = [x, y, z] 6 | 2. 7 | my_list = [1, 2, 3] 8 | x, y, z = my_list 9 | -------------------------------------------------------------------------------- /9.3.6 Coordinate Pair.py: -------------------------------------------------------------------------------- 1 | print((int(input("Number: ")), int(input("Number: ")))) 2 | 3 | #other type of code u can use: 4 | """ 5 | x = int(input("Number: ")) 6 | y = int(input("Number: ")) 7 | print((x,y)) 8 | """ 9 | -------------------------------------------------------------------------------- /9.3.7 Slopes.py: -------------------------------------------------------------------------------- 1 | mylist = [] 2 | for i in range(5): 3 | x = int(input("X Coordinate: ")) 4 | y = int(input("Y Coordinate: ")) 5 | mylist.append((x, y)) 6 | 7 | for i in range(4): 8 | y1 = mylist[i][1] 9 | x1 = mylist[i][0] 10 | y2 = mylist[i + 1][1] 11 | x2 = mylist[i + 1][0] 12 | 13 | 14 | slope = float(y2 - y1) / float(x2 - x1) 15 | print("Slope between " + str(mylist[i]) + " and " + str(mylist[i + 1]) + ": " + str(slope)) 16 | -------------------------------------------------------------------------------- /9.3.9 Full Name & Citation.py: -------------------------------------------------------------------------------- 1 | first = input("First name: ") 2 | last = input("Last Name: ") 3 | 4 | print("Full name: " + first + " " + last) 5 | 6 | first, last = last, first 7 | 8 | print("Citation: " + first + ", " +last) 9 | -------------------------------------------------------------------------------- /9.4.2 Dictionaries.py: -------------------------------------------------------------------------------- 1 | 1. print(my_dictionary["Bo"]) 2 | -------------------------------------------------------------------------------- /9.4.5 Phone Book.py: -------------------------------------------------------------------------------- 1 | my_dictionary = {} 2 | 3 | while True: 4 | name = str(input("Enter a name: ")) 5 | if name == "": 6 | break 7 | elif name in my_dictionary: 8 | print("Phone Number: " + my_dictionary[name]) 9 | else: 10 | phone_number = input("Enter this person's number: ") 11 | my_dictionary[name] = phone_number 12 | 13 | print(my_dictionary) 14 | -------------------------------------------------------------------------------- /9.4.6 Word Counts.py: -------------------------------------------------------------------------------- 1 | dictionary = {} 2 | text = input("Enter some text: ") 3 | text = text.split() 4 | for word in text: 5 | if word in dictionary: 6 | dictionary[word] = dictionary[word] + 1 7 | else: 8 | dictionary[word] = 1 9 | 10 | print(dictionary) 11 | -------------------------------------------------------------------------------- /9.5.2 Equivalence vs. Identity: -------------------------------------------------------------------------------- 1 | 1. yes 2 | 2. yes 3 | 3. yes 4 | -------------------------------------------------------------------------------- /9.5.6 Swapping.py: -------------------------------------------------------------------------------- 1 | def swap_lists(first, second): 2 | f = [second, first] 3 | print("After swap") 4 | print("list_one: " + str(f[0])) 5 | print("list_two: " + str(f[1])) 6 | 7 | list_one = [1, 2, 3, 4, 5, 6] 8 | list_two = [4, 5, 6] 9 | 10 | print("Before swap") 11 | print("list_one: " + str(list_one)) 12 | print("list_two: " + str(list_two)) 13 | 14 | swap_lists(list_one, list_two) 15 | -------------------------------------------------------------------------------- /9.5.7 Word Counts, Part 2.py: -------------------------------------------------------------------------------- 1 | text = input("Enter some text: ") 2 | 3 | text_list = text.split() 4 | 5 | dictionary = {} 6 | def update_counts(count_dictionary, word): 7 | if word in count_dictionary: 8 | count_dictionary[word] = count_dictionary[word] + 1 9 | else: 10 | count_dictionary[word] = 1 11 | 12 | for word in text_list: 13 | update_counts(dictionary, word) 14 | 15 | print(dictionary) 16 | -------------------------------------------------------------------------------- /9.6.1 Extending Data Structures Quiz: -------------------------------------------------------------------------------- 1 | 1. [10, 11] 2 | 2. print(my_list[1][2]) 3 | 3. Dictionary 4 | 4. 5 | 12 6 | 3 7 | 5 8 | 45 9 | 7 10 | 8 11 | 1 12 | 2 13 | 3 14 | 5. 15 | board = [] 16 | board.append([1, 2, 3]) 17 | board.append([4, 5, 6]) 18 | board.append([7, 8, 9]) 19 | 6. my_list = [i*2 for i in range(6)] 20 | 7. Storing multiple variables’ values by putting them in a collection, like a list or tuple 21 | 8. Initializing multiple variables at a time using a collection of values 22 | 9. 23 | coffee = "kona" 24 | tea = "mango" 25 | smoothie = "raspberry" 26 | 10. 27 | red = "BLUE" 28 | blue = "GREEN" 29 | green = "RED" 30 | 11. keys to values 31 | 12. 32 | oak 33 | daisy 34 | bindweed 35 | 13. I only 36 | 14. print(my_list[1:3]) 37 | -------------------------------------------------------------------------------- /Knowledge & Skills: Python: -------------------------------------------------------------------------------- 1 | 1. It is sunny and Sarah has 2 bags 2 | 2. Square 3 | 3. I and III 4 | 4. 12 5 | 5. x > 6 6 | 6. 3 7 | 7. A for loop repeats commands a specific number of times and a while loop repeats until a condition becomes false. 8 | 8. hellohellohello 9 | 9. 6 times 10 | 10. 100 11 | 11. float 12 | 12. 10 13 | 13. Yes 14 | 14. [“orange”, “yellow”, “red”, “green”, “blue”] 15 | 15. hi 16 | hi 17 | hi 18 | hello 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeHS-IntroIntoPython 2 | This repository includes answers and code to every quiz and assignment needed in CodeHS's course called "Intro to Computer Science in Python 3". 3 | 4 | To find a specific assignment click on the `Go to File` button near the top of all of the files and then type in the assignment number. 5 | 6 | Example: 10.1.2 (this will take you to the file named "Guess the Word, Part 1.py") 7 | 8 | 9 | # Quiz Answers Format 10 | 1. `answer here` 11 | 2. `answer here` 12 | 3. `and so on...` 13 | 14 | # Issues 15 | If you find any issues with the code please let me know by creating an issue. 16 | 17 | [Click here to go to the issues page](https://github.com/aditeyapatakoti/CodeHS-IntroIntoPython/issues) 18 | --------------------------------------------------------------------------------