Course Home
Announcements
Check Yourself
Python Errors in English
CodeSkulptor FAQ
Reflections

Online Lessons

Related Links

Online Development

Lessons

Reference

What's next?

Congratulations on completing Python: Games to Google!

Here are some ideas for continuing your adventures in coding:

  • Continue with Codecademy
  • Start or continue with CodingBat
  • Want to learn Java or develop your Java skills further? Check out Greenfoot.org. Greenfoot is a development environment for Java.
  • CTD generally offers a Java programming class in the fall (starting in October) for students in grades 6-8.
  • There is also an Introduction to Java Programming Honors course offered by CTD in the summer. Check the CTD catalog for more information about credit and prerequisites.

Friday, August 4

EXPO! Today!

Your priority for your EXPO! project should be to save a version that works, even if it doesn't have all the features you want to add. Remember, there is no such thing as an ultimate version of Word, or Excel, or Minecraft, or Windows. There are just versions. In general, users would rather have you fix bugs before adding any features.

Student Work

These are the latest versions I have of your work. If you have a more recent version, would like to post a different project instead, or would like to post an additional project, send it to me and I'll put it on the site.

What We Have Done

Codecademy, CodingBat, CodeSkulptor, Monty Python, Projects, Improvement of web crawler

What We Have Learned

Math and Physics

  • Variables
  • Operators (arithmetic, comparison, boolean)
  • Functions
  • Coordinate Systems
  • Boolean Logic
  • Modular Arithmetic
  • Vectors (position, velocity, acceleration)
  • Collision detection

Programming Paradigms

  • Imperative Programming (trinket.io, IDLE)
  • Procedural Programming (Codecademy, IDLE)
  • Functional Programming (CodingBat, IDLE)
  • Object-oriented Programming (Classes in Codecademy and CodeSkulptor, IDLE)
  • Event-driven Programming (CodeSkulptor SimpleGUI, IDLE tkinter)

Programming Concepts

  • Basic syntax and semantics of Python
  • Variables and data types (numbers, strings, booleans, lists, tuples)
  • Expressions and assignments
  • Conditional and iterative control structures (if, elif, else, for, while)
  • Functions and parameter passing

What do we do when we're done with our Expo projects?

Once you have a version that is complete, test it for bugs. Then ask someone else to test it. When you are satisfied that it is ready to demo, save your demo version. After that, you can work on adding features, or do some Codecademy, CodingBat, or continue working through the Google material on the course web site (Lists, Dictionaries, List Comprehensions, File I/O, Regular Expressions, Utilities).

You can also work on any Codecademy or CodingBat exercises you haven't completed.

To deepen your Python knowledge and programming skills see the Python for Everybody Specialization, a series of Python courses from the University of Michigan on the Coursera web site.

The Pong activity we did in class was based on an assignment in this Coursera course offered by professors at Rice University.

You can check out Google's Python Class.

Thursday, August 3

Course Survey

Let us know what you think about your Summer Program experience by taking this survey

Self-evaluation

Fill out this self-evaluation to let us know how you feel about your performance this session.

How Google Search Works

The video below explains the role of spiders in a Google search.

In class, we'll see how you can use BeautifulSoup and Python to find links on a web page and how to follow links like a spider does.

Sample problem for following links with following_links.py: Start at https://python-data.dr-chuck.net/known_by_Fikret.html
You should follow the link 4 times. Find the link at position 3 (the first name is 1). Follow that link.
Sequence of names: Fikret Montgomery Mhairade Butchi Anayah
Last name in sequence: Anayah

Pair programming: Improving following_links.py

The following_links.py file often fails when run against https://www.tjleone.com. Can you make it work better?

Pair programming: Improving Click Lines

One of the examples from the CodeSkulptor docs (Control Objects->Set the Mouse Input Handler) is Click Lines. It has the beginnings of a draw program. Customize it by adding text input boxes to:

  • Change the color of the lines
  • Change the thickness of the lines

Can you make your program check the input to make sure it is valid? For example, what are the valid colors you can use for drawing lines in CodeSkulptor? What is a good message to give to the user if the input is not valid? Can you make the message show up in a text label?

Cycling through colors

Here's a CodeSkulptor program that cycles through fill colors from red to yellow to green to cyan to blue to magenta and back to red.

Wednesday, August 2

Adding a Background Image

Agar.io

Here is the beginnings of an Agar.io game that Dorian and I worked on this morning.

Image Inspector

You can use this program to help figure out the parameters you need to get your image to show up correctly. If the program won't load properly in CodeSkulptor, you can copy and paste the code from this page.

Tuesday, August 1

Game Over

Recall this code from Codecademy(Functions - 6. Practice Makes Perfect):


def cube(number):
    return number ** 3
    
def by_three(number):
    if number % 3 == 0:
        return cube(number)
    else:
        return False
        

We'll review the terms function definition and function call and how we can use functions calling functions to make a Game Over screen for Pong.

Pair Programming: Pong to Breakout

Jiawei had the idea of modifying Pong to make it into a Breakout game. This makes a great pair programming activity, because it makes you think about how Pong works and makes you use what you know about CodeSkulptor, classes, lists, and functions.

The bricks for a game of Breakout have some things in common with the paddles in Pong:

  • They have a similar shape.
  • Our program needs to recognize when a ball hits a brick.

The differences are:

  • Paddles are moved with the keyboard and are always visible. Bricks don't move are not always visible.
  • When the ball hits a paddle, it bounces off of the paddle.
  • When the ball hits a brick, the brick disappears.
  • There are only two paddles in Pong. In Breakout, there is only one paddle, and there are lots of bricks.

One strategy for making new objects that are similar to other objects is to inheritance. In this activity, we'll create a Brick class that is a subclass of Paddle.

In order to handle lots of bricks, we'll put all our bricks in a list and use for loops to look at each brick to check for collisions with the ball and to see if the brick should be drawn.

Starter Code for Driver

The driver should start with the complete version of Pong from our last pair programming activity.

Instructions for Navigator

Our current Pong game has three classes: the Circle class, the Ball class, and the Paddle class. Look at these three classes. What keyword do you need to define a class? How can you tell that the Ball class is derived from from the Circle class?

Our Brick class will be just like our Paddle class, except we need an instance variable to keep track of whether or not the brick should drawn. To do this, we derive it from the Paddle class. Below the Paddle class, add a Brick class. Your header should begin with the keyword class and show that the Brick class is derived from the Paddle class. Inside the Brick class, add this __init__ method:

    def __init__(self, x, y, width, height):
        Paddle.__init__(self, x, y, width, height)
        self.is_visible = True
Make sure you use the proper indentation to show that the __init__ method is inside the Brick class.

Remove the code in the draw handler that draws paddle2.

Run the program. Make sure that you can no longer see paddle2.

Switch Roles

Find the new_game function. Copy the code that creates paddle2. Change the copied code to create an instance of Brick called brick.

Find the statement in new_game that makes paddle1 and paddle2 global variables. Make brick a global variable so you can use it in the draw handler.

Run the program and make sure you didn't break anything. Why can't you see the brick?

Add the code to the draw handler to draw the brick. You should also add a test to make sure the brick is visible. Use the is_visible instance variable of the brick object.

Switch Roles

After the code that draws the brick, you should add code to determine whether brick and ball have collided:

	# determine whether brick and ball collide
        if brick.hit(ball) and brick.is_visible:
            brick.is_visible = False
            spawn_ball(LEFT)
Why do we need to check if the brick is visible when we're testing for a collision? Why do we set is_visible to False at that point? Why do we spawn_ball(LEFT) at that point?

To test our code, let's make the brick really long so the ball can hit it easily. Create a new global variable called BRICK_HEIGHT. In the section where we set PADDLE_HEIGHT = 80, make the BRICK_HEIGHT 200. You should also create a variable called BRICK_WIDTH. For now, you can let the BRICK_WIDTH be 8.

Find the code in new_game where we instantiate our brick. Change the height of the brick from PADDLE_HEIGHT to BRICK_HEIGHT.

Test out the code to see if it works. Try changing the BRICK_WIDTH and make sure the code still works.

Switch Roles

Now that we have one brick working, let's figure out how to make a bunch of bricks. Instead of a brick variable that holds a single brick, we'll need a bricks variable that holds a list of bricks.

The first thing we'll need is a list. Find the code in new_game where you instantiate the brick. Change it to look like this:

    bricks = []
    bricks.append(Brick(WIDTH-BRICK_WIDTH/2,HEIGHT / 2 - BRICK_HEIGHT/2, BRICK_WIDTH, BRICK_HEIGHT))

You won't need the global variable brick any more, but you will need to make bricks a global variable so you can use it in the draw handler.

Now we need to change the draw handler to use the bricks list. It will stil only draw one brick for now.

Try this:

		
    # draw bricks
    for brick in bricks:
        if brick.is_visible:
            brick.draw(canvas)
    
    # determine whether bricks and ball collide
    for brick in bricks:
        if brick.hit(ball) and brick.is_visible:
            brick.is_visible = False
            spawn_ball(LEFT)
After you've tested your code, try adding more bricks to the bricks list in new_game. You will need to use the append method on the bricks object. Make the bricks smaller by changing BRICK_HEIGHT. The first two arguments you pass to Brick are the x and y coordinates of the brick. Make sure you don't put all the bricks in the same place!

Next steps to consider

  • Getting rid of the score text
  • Getting rid of any code that refers to paddle2
  • Testing to see if the game is over. This should happen when none of the bricks are visible. You can check this with a for loop.
  • Adding a Game Over screen.
  • Adding a button to restart the game.

Sample Projects from Past Classes

The Python turtle module

You are welcome to continue working on Breakout, or do any work you have left on Codecademy or CodingBat. If you would like to try something else, you can work on Python programming with turtles.

Here are some other resources for learning how to use the turtle module:

Monday, July 31

Goals for this week

I looked over everyone's self-evaluations this weekend. You've set some good goals for yourselves!

Games to Google

If you're interested in learning more about how Google works and how to build a simple web crawler in Python, prepare by making sure you've completed the File I/O unit by tomorrow morning.

If you've completed the File I/O unit in Codecademy, you can further prepare with the "Dicts and Files" material from Google's Python Class.

Codecademy and CodingBat

Some people were interested in making more progress in Codecademy and CodingBat. Feel free to spend as much time on that as you like. Just make sure that you're saving your Codecademy work as you go, since we've gotten a warning from Codecademy that work you've done might be erased this week (however, your record of progress won't change).

CodeSkulptor Project Ideas

Other people wanted to do more work with CodeSkulptor. Are you looking for CodeSkulptor project ideas, or help with work on your project idea? See below.

Working with Images

Today we'll look at the game shell Zuul for CodeSkulptor that you can use to create illustrated adventure games (You can click here for code to copy and paste if you can't open the other link in CodeSkulptor).

You can use this program to help figure out the parameters you need to get your image to show up correctly. If the program won't load properly in CodeSkulptor, you can copy and paste the code from this page.

Customizing Pong

A couple of people had the idea of make a Game Over screen for Pong. Here's some sample code that might help with that. If that program doesn't open properly in CodeSkulptor, you can copy and paste the code on this page.

From Tic tac toe to Battleship?

Here's a CodeSkulptor tic tac toe game for you to experiment with. Could you use it to make a CodeSkulptor version of Battleship?

PygLatin

Here's another project idea: Create a simplegui version of PygLatin that uses an input handler to get a word and then displays the word in the canvas with draw_text().

Here's some video help:

Game Classes I'm Working On

Here is a program with some classes I'm working on to help create more interesting games, in case you'd like to check it out.

Friday, July 28

Week 2 Self-Evaluation

Complete this self-evalution

CodeSkulptor Pair Programming: Pong with classes

Here's a Pong template with classes. If you can't bring up this program in CodeSkulptor, you can click here for code that you can copy and paste into CodeSkulptor.

To prepare for this exercise, we'll do a walkthrough of the classes you will use. Notice the parameters needed to instantiate objects or call methods on those objects, if any.

You will notice that the ball is instantiated in the spawn_ball function, and the paddles are instantiated in the new_game function.

Instructions for Navigator

  • Find the draw handler. This is where all changes will be made.
  • Find the comment that says # update ball. Below this comment, add a call to the update method of the ball object.
  • Find the comment that says # draw ball. Below this comment, add a call to the draw method of the ball object.
  • Find the comment that says # update paddle's vertical position, keep paddle on the screen. Below this comment, add a call to the update method for paddle1 and another call to update method of paddle2.
  • Find the comment that says # draw paddles. Below this comment, add a call to the draw method for paddle1 and another call to draw method of paddle2.

Switch Roles

  • Find the comment that says # determine whether paddle and ball collide. Below this comment, we need to add code that checks for collisions, then updates the right player's score and respawns the ball in the right direction. We'll also accelerate the ball each time it hits a paddle. Add this code below the comment:
    
        if paddle1.hit(ball) or paddle2.hit(ball):
            ball.dx = -ball.dx * BALL_ACCELERATION
            ball.dy *= BALL_ACCELERATION
        elif ball.in_left_gutter():
            score2 += 1
            spawn_ball(RIGHT)
        elif ball.in_right_gutter():
            score1 += 1
            spawn_ball(LEFT)
    
  • Finally, we need to draw the scores. Find the comment that says # draw scores. To locate the scores on the screen, you might try (WIDTH/4, 100) for score1 and (3*WIDTH/4, 100) for score2.

Save Codecademy Work for EXPO!

According to email from Codecademy, your progress in their Python course will be kept, but the code you've written will be removed some time during the week of August 1, which is next week. Everyone should save at least one Codecademy project (PygLatin, Taking a Vacation, A Day at the Supermarket, Student Becomes the Teacher, Battleship, Practice Makes Perfect, Exam Statistics, or anything from later lessons). Save the lesson to a file in IDLE, and make sure you can run it and explain what it does.

Quizlet

After Quizlet Live, take this quiz.

Class and Instance Variables

Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class:

class Dog:

    kind = 'canine'         # class variable shared by all instances

    def __init__(self, name):
        self.name = name    # instance variable unique to each instance

>>> d = Dog('Fido')
>>> e = Dog('Buddy')
>>> d.kind                  # shared by all dogs
'canine'
>>> e.kind                  # shared by all dogs
'canine'
>>> d.name                  # unique to d
'Fido'
>>> e.name                  # unique to e
'Buddy'

Homework ideas

If you haven't finished Introduction to Classes in Codecademy, you should work on that.

If you have finished Introduction to Classes, you can go back and complete other lessons in Codecademy that you haven't gotten to yet.

You can work on CodingBat problems you haven't tried.

You can check out the game shell Zuul for CodeSkulptor that you can use to create illustrated adventure games (You can click here for code to copy and paste if you can't open the other link in CodeSkulptor).

Here is some code to help with adding images to CodeSkulptor.

You can also check out the Google Python Class. There are some interesting problems in the Dicts and files section and beyond.

Thursday, July 27

CodeSkulptor Pair Programming

For this exercise, we'll start with this simple pong template. This program implements the requirements and challenges from yesterday's exercise, except for Extra Challenge #4, so there's only one paddle and one player. If the player misses the ball with the paddle, the ball goes to the middle of the screen so the player can try again. If the ball goes off the court on the left, it disappears, and you have to quit out of the window and start a new game. To prepare for today's exercise, we'll review how it works.

If you can't open the file in CodeSkulptor, click here and copy and paste the code that appears.

As you work through the code, keep an eye out for comments that start like this:

# +++ADD CODE HERE

Instructions for Navigator

In this simple version of Pong, there is only one paddle and one player. Your task is to add scoring. At the beginning of the game, the score is 0. The player should score when the ball goes off the screen to left. At that point, the score should be updated and the new score should be drawn. At the same time, the ball should move back to the middle of screen so that the player can continue playing.

  • In the "Initialize Globals" section of your program, create a variable to keep track of the score. Initialize it to 0.
  • In the draw handler, add code to update the score.

Switch Roles

  • In the draw handler, add code to draw the score. You will need to call the draw_text method on the canvas object in the draw handler. The draw_text method expects its first argument to be a string, so you will have to convert the score to a string with the str function.

CodingBat Pair Programming

Do one problem from String-1, then switch roles and do another one.

Codecademy Goal for Today

Get through Introduction to Classes. If you're finished with Classes, you can do more Codecademy or CodingBat, develop Pong further, or check out some of these CodeSkulptor videos.

Artificial Emotions

Researchers have been working hard to develop artificial intelligence. Do you think we should try to develop artificial emotions? Why do humans have emotions? Would emotions be a good thing for machines to have? Why or why not?

Homework

Apogee students are expected to do one hour of homework.

Job One is to finish Introduction to Classes in Codecademy. After that is done, you can do any of the following:

  • More Codecademy
  • More CodingBat
  • Continue improving Pong
  • Work with the turtle module in IDLE or trinket.io
  • More CodeCombat

Wednesday, July 26

CodingBat Pair Programming

We'll go through match_ends from list1.py as a group. With your pair programming partner, do count_evens from List-2.

CodeSkulptor Pair Programming

To prepare for this exercise, we'll start with a closer look at the parts of a CodeSkuptor program, especially:

  • creating a frame
  • registering handlers
  • starting a frame

Open this Pong paddle program.

If you can't download the file, click here and copy and paste the code that appears.

  • Move the paddle all the way to right side of the canvas. Make sure you can still see the whole paddle.
  • Add tests so that the paddle doesn't go off the screen.
  • Add code to the draw method that draws a circle in the middle of the canvas for your Pong ball.

Extra Challenge #1

Make the ball move.

Extra Challenge #2

Make the ball bounce off the top and bottom of the canvas, but let it go through the side walls.

Extra Challenge #3

Make the ball bounce off the paddle

Extra Challenge #4

Add a second paddle to the left side of the canvas.

Quizlet Live

Here's the quiz to take after Quizlet Live.

Tuesday, July 25

Lists

Today we're going to check out lessons on lists and more lists from Google's Python Class.

After that, download list1.py and try working the exercises.

It's OK if you do not complete all the functions, and there are some additional functions to try in list2.py.

Quizlet Live

After Quizlet Live, take this quiz.

Monday, July 24

Outdoor Safety

Avoiding unnecessary roughness, and what to do if someone is injured.

Using IDLE

Before we begin our first lesson from Google's Python Class, let's make sure we can:

  • Run an existing python program, such as hello.py
  • Run the Python interpreter interactively, so you can type code right at it

Strings Review: String Basics

After we work through String Basics, download string1.py and we'll walk through the donuts exercise.

Strings Review: String Slices

When that work is complete, we'll work through the video on String Slices and make pairs to work through both_ends and fix_start. If you finish those, try more of the exercises in the file. If you finish those, go to CodingBat and do some more exercises from String-1.

Codecademy

Everyone should finish Lists & Dictionaries today. If you don't get through it during the day, work on it for homework.

Quizlet Live

CodeSkulptor Pair Programming

  1. Open up codeskulptor.org
  2. On line 11, create a variable named position and intialize it to [50, 112]
  3. In the draw() event handler, replace [50, 112] with the variable position
  4. Test to make sure that the program still works.
  5. In the draw handler, add the line

    position[0] += 1

  6. Test the program again. What happens? Why?

Switch Roles

  1. Starting at line 10, add these lines:

    WIDTH = 300

    HEIGHT = 200

    FONT_SIZE = 48

  2. Add this line to your draw handler after position[0] += 1:
    
            if position[0] >= WIDTH:
                    position[0] = 0
    
    
  3. Test the program. What happens? Why?
  4. We can make scrolling a little smoother if we start the text farther to the left. frame.get_canvas_textwidth(message, FONT_SIZE) will give us the length of the message string for the given FONT_SIZE. Try changing the if statement in your draw function to this:

    if position[0] >= WIDTH:

    
            position[0] = -frame.get_canvas_textwidth(message, FONT_SIZE)
    
    
  5. Test out your change. What happens? Why?
  6. It would be nice if clicking the button could toggle the text back and forth between "Welcome!" and "Good job!"
  7. Try changing your click() function like so:
    def click():
        global message
        if message == "Welcome!":
            message = "Good job!"
        else:
            message = "Welcome!"
    

Programming with the turtle module

Check out A Visual Introduction to Python to learn how to program with the turtle module.

Friday, July 21

Python installations

Today let's make sure everybody has a local version of Python installed. By the way, who is Eric Idle, and why is IDLE named after him?

Self evaluation

Complete this Self Evaluation to let me know how you feel about what you've accomplished this week.

Quizlet Live Today

To be ready for today's Quizlet Live, you must complete all Codecademy exercises in Lists and Dictionaries through number 9, More with 'for'

After Quizlet Live, take this quiz

CodingBat Pair Programming

We'll do List-1 > first_last6 together as a group, then pair up for same_first_last and make_pi.

Thursday, July 20

An interesting error

What does it mean when you get the error "maximum recursion depth exceeded"?

Video lesson

This morning, use the video below to modify this CodeSkulptor program. If the program won't open for you in CodeSkulptor, you can open this page to copy and paste the code into CodeSkulptor.

When you're finished working through the video, you should have a Python app with a button that makes the circle grow.

Button Challenges

  • Add a button that makes the circle shrink
  • Add a button that changes the fill color of the circle to red.
  • Add a button that makes the line around the circle thicker or thinner.
  • Add a button that moves the circle left or right (Hint: you will need to use center_point[0])
  • Add a button that moves the circle up or down (Hint: you will need to use center_point[1])

Try to add the buttons on your own, but if you need help, you can use this template to start yourself off.

For more help, see the video below.

What do I do when I'm done?

  • You can experiment some more with buttons and drawing.
  • You can work on Codecademy

This morning's trinket

CodingBat Pair Programming

We'll do a Logic-1 problem together. Then we'll choose pairs to work a couple more Logic-1 problems.

Wednesday, July 19

CodingBat Pair Programming

This morning I want to spend more time talking about how CodingBat works before we get started. We'll review a couple of String-1 problems and do a Logic-1 problem together. Then we'll choose pairs to work a couple of Logic-1 problems.

CodeSkulptor Pair Programming

Driver will work start with our moving ball exercise from yesterday. If the program won't load in CodeSkulptor, cut and paste this program.

Instructions to be read by Navigator

  1. Run the program. Notice that we now have a button in the control area that says "Click me". Does anything happen when you click the button? Look at the code. Where does the program tell CodeSkulptor to add a button? Why doesn't the button do anything?
  2. Why isn't the circle moving? Look at the values of dx and dy.
  3. Let's start the circle moving by adding code to the click function. How do you know that the click function will be called when a button is pressed?
  4. Change the line in the click function that says pass to make it say global dx, dy. After global dx, dy, add a line that says dx = 1 and a line that says dy = 1.
  5. Run the program again and try clicking the button.

Switch roles one more time

  1. Let's get the circle to bounce when it hits the edge of the canvas.
  2. First, you should notice that you can change the movement of the circle in the x direction by changing the sign of dx, and you can change the movement of the circle in the y direction by changing dy. Why?
  3. When should we change movement in the x direction? When we hit the left or right side of the canvas. For a first try, change your draw handler to look like this:
    
    def draw_handler(canvas):
        global x, y, dx, dy
        x += dx
        y += dy
        if x <= 0 or x >= canvas_width:
            dx = -dx
        elif y <= 0 or y >= canvas_height:
            dy = -dy
        canvas.draw_circle((x,y), radius, line_width, line_color, fill_color)
    
  4. Challenge #1: Do you notice how this bouncing isn't quite right? Can you change the conditions so that the ball bounces right when it hits the edge of the canvas?
  5. Challenge #2: Can you put two circles on the canvas that bounce when they hit each other?

Homework options

In addition to the usual options of Codecademy or CodingCombat, you can also check out this Python Hour of Code

Tuesday, July 18

Homework Check-in

Any problems with homework last night? When you get stuck on an exercise, a good resource is the Python Discussion Forum.

CodeSkulptor Review

We'll over the work people did on CodeSkulptor in pair programming yesterday.

CodingBat Pair Programming Assignment

I created CodingBat logins for everybody last night. You log in with your email address.

We'll create random pairs and do two CodingBat assignments. Then, you will do the following:

  • Decide which of you will be the Navigator and which be the Driver for the first assignment.
  • For the first assignment, the Driver needs to log in to CodingBat and go to the first String-1 exercise on the CodingBat site, called hello_name.
  • To log in, use your email account for id/email. I'll give you the password in class.You must be logged in so that your progress can be tracked properly
  • Navigator and driver should complete this exercise.
  • When you are finished with hello_name, Navigator and Driver should switch roles.
  • The new Driver should log in to CodingBat and do the next exercise in String-1 called make_abba.

When you are done, make sure that both of you have complete working answers for both exercises.

Quizlet.live later today

Be sure you're familiar with the Strings material for our Quizlet Live session.

After Quizlet.live, test yourself on the string methods with this TestMoz quiz. Don't forget to sign in with your first and last name.

Pair Programming with CodeSkulptor: Refactoring

When you go to CodeSkulptor.org you see an example of a program you can run that has a click method. The first line inside the click method says global message. In this pair programming exercise, you'll see how the global keyword can help you make a circle move around the screen.

The Driver should open this program.

Instructions to be read by Navigator

In the Welcome! example we saw how the global keyword was used with the message variable in the button handler so we could change the message. We're going to make x and y global in our draw handler so we can change the values of x and y.

  1. Put your cursor at the end of line 14 by clicking at the end of that line (after the colon) with your mouse. Press Enter
  2. Add a line that says global x, y. This will allow you to change the global variables x and y inside the draw_handler function.
  3. After the line with the global statement, add a line that says x += 1.
  4. Run the program. What happens? Why?
  5. After the line that says x += 1, add a line that says y += 1. What do you think will happen? Why?
  6. Run the program. Did it do what you expected? Why or why not?

Time to switch roles

It would be cool if the circle could bounce whenever it hit the edge of the canvas. The program we have now makes the circle go off the screen because we always add 1 to x and we always add 1 to y. To be able to change the values we add to x and y, we will replace the 1 we add to x with a variable dx. We'll replace the 1 we add to y with the variable dy.

This part of our exercise will not change the way program works. The changes below make our code clearer and more flexible so that we can implement bouncing tomorrow. These kinds of changes are called refactoring.

  1. Under the statement fill_color = 'White', add a line that says dx = 1. The variable dx is commonly used to stand for the change in x.
  2. Add another line that says dy = 1.
  3. Change the line that says x += 1 to say x += dx.
  4. Change the line that says y += 1 to say y += dy.
  5. Run your program to make sure it still works correctly.
  6. What happens when you change the values of dx and dy?

We are now ready to make the ball bounce when it reaches the edge of the screen. In order to do that, we'll need to use conditionals.

Monday, July 17

Welcome to Python Programming: From Games to Google!

We will spend the morning getting acquainted with each other and start exploring Python.

Logistics

  • Bathroom. Students need to be accompanied by an adult to the bathroom. Your class guides (TJ, and Sarah) would like to be available as much as possible to help you with your work, so we'll schedule whole class bathroom breaks. One of us will accompany anyone any time they need to go, but try to go during scheduled breaks.
  • Outdoor breaks. We'll make time each day to get outside. You'll leave for lunch around 10:45am so you can be in the lunch room by 11:00am. We will also take an afternoon break outdoors around 1:25pm
  • Pomodoro breaks. We will also take short Pomodoro breaks so we have some kind of break every 25 minutes or so.
  • Food and Drink. Students can bring food and drink for break time. You can drink water in the classroom if it is in a water bottle.
  • Lunch. Students will leave for lunch with their TAs at 10:45am and return to the classroom around noon. This will give you time to walk to the cafeteria, eat, and then have some time to hang out or play outside.
  • Laptops cannot be left unattended. If your instructor and TAs are all leaving the room the same time as you, you'll have to take your laptop with you.
  • Noise Level. There are Northwestern students and faculty at work in this building. Noise level should be adjusted appropriately, especially in hallways.
  • Homework. CTD requires one hour of homework per day. We'll go over details this afternoon, when it will make more sense.
  • Headphones. If you have your own ear buds or headphones, you are welcome to bring them. Otherwise, headphones will be provided to you.

Getting to Know Each Other

Let's take some time this morning to learn a little about each other.

Fill out this survey so we have an idea the knowledge you have to share and what you want to learn.

How do you learn best?

Getting Started

You don't need to install Python to program in Python. Here's how to get started:

  • Send an email to me so I'm sure I have your correct email address. If you don't have email, let us know and we'll set you up.
  • Get your Codecademy login from TJ or Sarah. Log in to Codecademy and start learning some python!
    • If you already have a Codecademy account: Give us your Codecademy login name. If you've already started on Codecademy Python exercises, pick up where you left off.
    • If you haven't done any Python exercises in Codecademy but you already know some Python: Look at the categories in the course syllabus. Is there anything there that you haven't learned about yet, or would like to review? Skip to that section. Not sure if you know the material in a section? Try working on a project in that section (for example, for the Python Syntax section, try the Tip Calculator). If you need help completing it, you might need to go over the lessons for that section (for example, the Python Syntax lessons for Python Syntax).
    • If you feel that you know all the material in the Codecademy lessons, do some exercises from Warmup-1 or Warmup-2 in CodingBat. Make sure you get a login name first and make sure you are set up properly so you can get credit for your progress!
  • After you've done a few exercises, feel free to do some more, or check out the material below that compares Python to other programming languages.

Comparing Python to Other Programming Languages

Here is a nice overview of Python using an environment similar to Scratch. It's a good place to start if you've mostly programmed in Scratch or if you haven't programmed at all.

If you have experience with Java or some object-oriented flavor of C (such as C++, C# or Objective-C) or with JavaScript, Here is some material that compares the basics of Java and Python.

Getting Help

We'll discuss different ways to get help from your peers, class guides, and the internet. For now, a good Codecademy resource is the Python Discussion Forum. You can also raise your hand. Guides will try to work with students in an order and length of time that seems fair. We'll work out a more formal way of spreading our expertise as the course goes forward.

Review of survey

Some time after our first break, we'll go over the survey as a group

Pair Programming

We'll watch a video on pair programming. If time permits, we'll start our first pair programming activity today. While you work, remember the pair programming do's and don'ts:

Pair programming Do's and Don"ts

Do

  1. Talk
  2. Listen
  3. Rotate Roles
  4. Be Patient
  5. Respect
  6. Take Breaks
  7. Prepare
  8. Clean
  9. Have Fun

Don"t

  1. Be Bossy
  2. Be Intimidated
  3. Be Quiet
  4. Suffer in Silence

Pair programming instructions

  • Pairs will be randomly assigned by a program written in Python.
  • The Driver for each pair will open up the first Python program.
  • The Navigator will open up this form
  • As you work through this program, you will be prompted to switch seats with your partner in order to switch laptops and roles.
  • If you were the Driver, you are now the Navigator. Continue filling out the form your partner was using.
  • If you were the Navigator, you are now the Driver. Continue working on the program your partner was using. When your partner tells you it's time top open a new program, open the Python program with variables.

Code of Conduct

Every work environment needs ground rules to keep things running smoothly. Here are some to get us started:

  • Treat others as you would like to be treated.
  • Respect other people and their property.
  • Laugh with anyone, but laugh at no one.
  • Be responsible for your own learning.
  • Do not disturb people who are working.

We'll discuss ground rules throughout the course, and add or change rules as needed.

What should be the consequences for breaking a rule? Here are three types I use:

  • You break it, you fix it.If something is taken, it should be returned. If something is broken, it should be replaced. If someone is physically or emotionally hurt, the damage should be repaired.
  • Temporary loss of privilege. If someone misuses bandwidth, they temporarily lose internet access.
  • Take a break. Sometimes students need some time away from a situation to clear their heads.

Any other ideas?

What should be the consequences for following the rules? We'll discuss this more in days to come.

Developing Talent

Since we're part of the Center for Talent Development, we need to discuss how to make this classroom a good place for developing talent. This is another topic we'll come back to throughout the course.

  • Everyone in this room has demonstrated the potential to develop cool software. Your job over the next three weeks is to develop that talent.
  • Each of you are already at different points in developing that potential. It will take more or less effort for you to develop your talent in different parts of the course. The thing to focus on is maintaining the effort to improve.
  • In order to create an atmosphere that supports continual development, part of your job is to encourage others.

Where Did Python Get Its Name?

Python was not named for the snake. It's inventor, Guido van Rossum, had a different Python in mind.

Python Setup

You can do most of the Python exercises through your browser, but at some point in the course, you'll probably want to run Python locally. Check out this web page to see if you already have Python installed and make sure you have the right version. If you need help with installation, Sarah and I will be available, and there will probably be other students who can help you as well.

A local version of Python won't be necessary until some of the later activities. As long you have a working browser, you'll be able to complete all the activities for at least the first week.

Code Combat

Sarah will show you how to get into CodeCombat and join the class.

Homework

For your homework, you can:

  • Work on material from any of the course web pages
  • Continue working on Codecademy
  • Play CodeCombat. If you choose to work on CodeCombat, you are expected to create an account to keep track of your progress.
  • Another thing you might like to try is trinket.io.

About the Center for Talent Development

Center for Talent Development (CTD), housed at Northwestern University's School of Education and Social Policy, is an accredited learning center and research facility that identifies, educates and supports gifted students and their families and serves as a leader in gifted education. Learn more about the Center for Talent Development.