Posts

Getting on with Graphics

We've done some reviewing of PyGame in the last few weeks (see https://inventwithpython.com/pygame/chapter2.html ).  Now we're going to write our own graphical game (the idea for this game was taken from here: https://inventwithpython.com/invent4thed/chapter19.html). Purpose:  Learn how to handle mouse and keyboard events to allow a user to interact with our games and to learn to handle collision events. To start get the outline setup with initializing pygame, drawing a window with a title, and setting up our main game loop that handles the quit event so we can exit out of our game.  It probably makes sense to have the window have a white background as well. Our game will crate a larger rectangle that is controlled by the keyboard.  When we start the game we will draw lots of food rectangles that are a different color from the player rectangle and will be much smaller.  When the player controlled rectangle runs into a food rectangle it will "eat" it and the food

Functions and Iterations and Strings. Oh my!

I thought about breaking up this post but decided not to.  The material here will probably take 2-3 weeks to get through so take your time and learn it well.  It isn't important to learn every nuance, but it is important to understand why certain things work the way they do. Read chapter three, "Functions". Do all five exercises in the chapter. Explain in your own words why breaking a large program into smaller functions can be useful. Read chapter six, "Fruitful Functions". Also read 5.8-5.10 on recursion as this chapter expands on that and we skipped those sections earlier. Do all 8 exercises in this section.  You might need some help understanding a few of the exercises, don't hesitate to ask. Read chapter seven, "Iteration".  Do the 5 exercises in this chapter. Read about the Python keyword 'continue'.  Explain the difference between 'break' and 'continue'. Read chapter eight, "Strings"  Do t

Conditional Execution

Read the first half of of "Think Python" chapter five on Conditionals and Recursion, 5.1-5.5. Write a statement in the interpreter that prints out the last three digits of the number 10245 using the modulus operator. In the interpretor set x=2, y=5 and evaluate the following: x==y, x!=y, x<y, x>y, x<=y, x>=y.  Now in your head set x=5, y=5 and figure out how those six statements would evaluate.  Run them through the interpreter and see if you were right.  Come up with a value for n that would make the following statement True: (n%2==0 and n%3==0). Test this in the interpreter. Would the following statements be True or False for x=3 and y=4, test them after you get your answer to verify:   not x>y x<y or x==y not x==y x<y and x<=y x<y or x<=y Programming Merit Badge requirement 2 :  Give a brief history of programming, including at least three milestones related to the advancement or development of programming. Discuss  the histo

Introduction to Python and Programming

I'm not sure on pacing yet, I'll put down what I hope we can get through in a week, but if we don't get to it all we can move some to next week. First off we're going to install a few things that we'll be using.  Go to the Python website and install the latest version of Python (3.6) on our computer.  Follow the instructions to install Pygame as well, we won't be using it right away but later. Read the first chapter of "Think Python" and answer the following questions: What's the difference between a compile and an interpreted programming language? Give three examples of natural languages, two examples of functional languages. What are the three types of errors mentioned in the chapter?  Which do you think can cause the most problems in a program?  Why? Start the Python interpreter (IDLE) and play around a bit.  Use it as a calculator.  Did you get the four basic math functions (add, subtract, multiply, divide)?  How do you do exponents?