Table of Contents

[hemmerling] Python 6/10 - Education in Python

Related pages:

Coursera "Computer Science 101"

Coursera "An Introduction to Interactive Programming in Python"

The Website

Reviews

The Course

General Timetable

Mini-project # 1 - Rock-paper-scissors-lizard-Spock

Timetable
Mini-project description - Rock-paper-scissors-lizard-Spock
Mini-project development process
  1. Build a helper function name_to_number(name) that converts the string name into a number between 0 and 4 as described above. This function should use an if/elif/else with 5 cases. You can use conditions of the form name == 'paper', etc to distinguish the cases.
  2. Next, you should build a second helper function number_to_name(num) that converts a number in the range 0 to 4 into its corresponding guess as a string.
  3. Build the first part of the main function rpsls(guess) that converts guess into the number player_number between 0 and 4 using the helper function name_to_number.
  4. Build the second part of rpsls(guess) that generates a random number comp_number between 0 and 4 using the function random.randrange(). I suggest experimenting with randrange in a separate CodeSkulptor window before deciding on how to call it to make sure that you do not accidently generate numbers in the wrong range.
  5. Build the last part of rpsls(guess) that determines and prints out the winner. This test is actually very simple if you apply modular arithmetic (% in Python) to the difference between comp_number and player_number. If this is not immediately obvious to you, I would suggest reviewing our discussion of remainder / modular arithmetic and experimenting with the remainder operator % in a separate CodeSkulptor window to understand its behavior.
  6. Using the helper function number_to_name, you should produce four print statements; print a blank line, print out the player's choice, print out the computer's choice and print out the winner.
  7. This will be the only mini-project in the class that is not an interactive game. Since we have not yet learned enough to allow you to play the game interactively, you will simply call your rpsls function repeatedly in the program with different player choices. You will see that we have provided five such calls at the bottom of the template. Running your program repeatedly should generate different computer guesses and different winners each time. While you are testing, feel free to modify those calls, but make sure they are restored when you hand in your mini-project, as your peer assessors will expect them to be there.
  8. The output of running your program should have the following form:
Player chooses rock\\
Computer chooses scissors\\
Player wins!\\
Player chooses Spock\\
Computer chooses lizard\\
Computer wins!\\
Player chooses paper\\
Computer chooses lizard\\
Computer wins!\\
Player chooses lizard\\
Computer chooses scissors\\
Computer wins!\\
Player chooses scissors\\
Computer chooses Spock\\
Computer wins!\\
Grading rubric - 16 pts total (scaled to 100 pts) # 1
Evaluation # 1

Mini-project # 2 - "Guess the number"

Timetable
Mini-project description - Guess the number
Mini-project development process
Grading rubric - 11 pts total (scaled to 100 pts) # 2
Evaluation # 2

Mini-project # 3 - Stopwatch: The game

Timetable
Mini-project description - Stopwatch: The game
Mini-project development process
Grading Rubric - 13 pts total (scaled to 100 pts)
Evaluation # 3

Mini-project # 4 - Pong

Timetable
Mini-project description - Pong
Mini-project development process
  1. Add code to ball_init to start the ball in the middle of the table and give the ball a fixed velocity (for now). Ignore the parameter right for now.
  2. Add code to the program template that draws a ball moving across the Pong table. We recommend that you add the positional update for the ball to the draw handler.
  3. Modify your code such that the ball collides with and bounces off of the top and bottom walls. Experiment with different hard-coded initial velocities to test your code.
  4. Add randomization to the velocity in ball_init(right) The velocity of the ball should be upwards and towards the right if right == True and upwards and towards the left if right == False. The exact values for the horizontal and vertical components of this velocity should be generated using random.randrange(). For the horizontal velocity, we suggest a speed of around random.randrange(120, 240) pixels per second. For the vertical velocity, we suggest a speed of around random.randrange(60, 180) pixels per second. (You will need to set the signs of speeds appropriately.)
  5. Add code that tests whether the ball touches/collides with the left and right gutters. (Remember that the gutters are offset from the left and right edges of the canvas by the width of the paddle.) When the ball touches a gutter, use ball_init(right) to respawn the ball in the center of the table headed towards the opposite gutter.
  6. Next, add code that draws the left and right paddles in their respective gutters. The vertical positions of these two paddles should depend on two global variables. (In the template, the variables were paddle1_pos and paddle2_pos.)
  7. Add code that modifies the values of these vertical positions via an update in the draw handler. The update should reference two global variables that contain the vertical velocities of the paddles. (In the template, the variables were paddle1_vel and paddle2_vel.)
  8. Update the values of these two vertical velocities using key handlers. The “w” and “s” keys should control the vertical velocity of the left paddle while the “Up arrow” and “Down arrow” key should control the velocity of the right paddle. In standard Pong, the left paddle moves up at a constant velocity if the “w” key is depressed and moves down at a constant velocity if the “s” is pressed and is motionless otherwise. (The motion if both are pressed is up to you.) To achieve this effect, you will need to use both a keydown and a keyup handler to increase/decrease the vertical velocity in an appropriate manner.
  9. Restrict your paddles to stay entirely on the canvas by adding a check before you update the paddles' vertical position.
  10. Modify your collision code for the left and right gutters to check whether the ball is actually striking a paddle when it touches a gutter. If so, reflect the ball back into play. This collision model eliminates the possibility of the ball striking the edge of the paddle and greatly simplifies your collision/reflection code.
  11. To moderately increase the difficulty of your game, increase the velocity of the ball by 10% each time it strikes a paddle.
  12. Finally, add scoring to the game as shown in the Pong video lecture. Each time the ball strikes the left or right gutter (but not a paddle), the opposite player receives a point and ball is respawned appropriately.
Grading Rubric - 19 pts total (scaled to 100 pts)
Evaluation # 4

Mini-project # 5 - Pairs

Timetable
Mini-project description - Pairs
Mini-project development process
Grading Rubric - 11 pts total (scaled to 100)
Evaluation # 5

Mini-project # 6 - Blackjack

Mini-project description - Blackjack
Mini-project development process
Tips
def draw(self, canvas, pos)
    for c in self.cards:
         c.draw(canvas,  ...)
         ....
Grading rubric - 18 pts total (scaled to 100)
Evaluation # 6

Mini-project # 7 - Spaceship

Timetable
Mini-project description - Spaceship
Mini-project development process
Phase one - Spaceship
Phase two - Rocks
Phase three - Missiles

Make sure that the missile sound is passed to the spriteconstructor so that you will get the shooting sound whenever you shoota missile.

Phase four - User interface
Grading rubric - 20 pts total (scaled to 100 pts)
Grading Instructions

Mini-project # 8 - RiceRocks

Timetable
Mini-project description - RiceRocks (Asteroids)
Mini-project development process
Phase one - Multiple rocks
Phase two - Collisions
Phase three - Missiles
Phase four - Collisions revisited
Phase five - Finish it off
Bonus
Grading rubric - 13 pts (scaled to 100 pts)
Grading Instructions

Communications

Python Code Structure & Process Steps ( for this Seminar, for SimpleGUI,.. )

# SimpleGUI program template

# 1 Import the module
import simplegui

# 2 Define global variables (program state)

# 3 Define "helper" functions

# 4 Define classes

# 5 Define event handler functions

# 6 Create a frame

# 7 Register event handlers

# 8 Start frame and timers

Course Material

Google

Google's Python Class

Google Code "trypython. Python tutorial in the browser with Silverlight / Moonlight"

UDACITY

UDACITY "Introduction to Computer Science (cs101) Building a Search Engine"

Unit 1

UDACITY "Design of Computer Programs (cs212). Programming Principles"

UDACITY "Web Development (cs253). How to Build a Blog"

UDACITY "Programming Languages (cs262). Building a Web Browser"

UDACITY "Artificial Intelligence for Robotics (cs373). Programming A Robotic Car"

Resources

edX

Udemy

Medialinx IT-Academy

The Course "Python in the System Administraton"

1 Python Basics

  1. Important data structurs:
    • Lists, strings and dictionaries.
  2. Python Help for Self-helping:
    • The Python interpreter shell.
  3. Syntax specialities:
    • Raw strings.
    • Function calls.
    • Lambda functions.

2 Important Libraries ( 7 of 100 )

  1. System specific parameters and functions.
  2. Features of the operating system.
  3. Display and transformation of time.
  4. Handling of processes.
  5. Regular expressions.
  6. Editing of pathnames.
  7. Comfortable file and directory operations.

3 Applications

  1. Word count in strings, files and Internet resources.
  2. Using a dictionary for data analysis.
  3. Filtering, sorting and modifying files in a directory structure.

CheckIO

Joe Perry

Markus Zapke-Gründemann

Resources

Forums, Newsgroups

Coursera

Google

UDACITY


When this document changes ! Site Navigation ( My Business ! My Topics ! Imprint / Contact ! Privacy Policy ! Keyword Index ! ! Google+ Publisher "hemmerling" )