100% found this document useful (1 vote)
286 views

Python Class Exercises 5-22-2012-1

The document provides a series of Python exercises involving operators, expressions, and programming tasks. It asks the user to evaluate mathematical expressions, compare strings, use functions like pow(), and modify existing Pygame code to create new games involving dodging enemies and breaking blocks. The exercises are to be saved in a Word document with the user's name and completed using Python 2.7.

Uploaded by

spreemouse
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
286 views

Python Class Exercises 5-22-2012-1

The document provides a series of Python exercises involving operators, expressions, and programming tasks. It asks the user to evaluate mathematical expressions, compare strings, use functions like pow(), and modify existing Pygame code to create new games involving dodging enemies and breaking blocks. The exercises are to be saved in a Word document with the user's name and completed using Python 2.7.

Uploaded by

spreemouse
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: _____________________________ Date:_______

Use Python 2.7 to complete the following Exercises. Save the output of the following exercise in a word document called pythonExercises522_YourNameHere.docx

Operators: Python commands are called statements. One kind of


statement is an expression statement, or expression for short. Like any programming language, Python can evaluate basic mathematical expressions. 1. For each of the following expressions, what value will the expression give? Verify your answers by typing the expressions into Python. a. 9-3 b. 8*2.5 c. 9/2 d. 9/-2 e. 9%2 f. 9%-2 g. -9%2 h. 9/-2.0 i. 4+3*5 j. (4+3)*5 2. State whether each expression listed here evaluates to True or False: a. g == "g" b. g == G c. a b d. ant < abc e. ant > Ant f. ant > Abc g. ant < anti

Name: _____________________________ Date:_______


3. We can calculate 24 using the power function pow by writing pow(2,4) at a command prompt. a. Write the statement used to calculate 5 to the power of 4. b. What does the statement pow(7,5) return? 4. What does the statement: 'Intro to Python'.swapcase() return? 5. What does the statement: 'Python Programming'.swapcase().endswith('MING') return?

Programming Task: 1. Enter the program code in a new editor window using Python 2.7 2. Create a working Pygame that allows a player to accumulate points by dodging bad guys while ominous music plays. 3. Modify the code by changing player.png, background.mid and baddie.png to reflect your choice of player, music and bad guys. 4. Create a working Pygame that allows a player to break blocks with a horizontal surface and a ball. 5. Modify the code by changing: the blocks, the ball and the surface the ball bounces off of.

You might also like