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?  Can you figure out what the modulus operator does (%)?

Read the second chapter of "Think Python" about variables, expressions and statements.
  • What are some examples of data types in Python?
  • What is a variable?
  • What is the difference between the Python interactive mode and the script mode?
Go back to the Python interpreter and play around with variables and expressions.  Make sure to play around with strings and numbers.  Try concatenating two strings together into a new variable. 

FIRST PROGRAM
From the interpreter create a new file, save it as "program1.py" or something similar.  Now write a program that asks the user for their name, and then says hello to them.  Using the link to the Python documentation read about the print function, and the input function.   Here is an example of what the screen could look like when you run your program:

What is your name?
Bob
Hello Bob!


That program was fairly simple and could be done in two lines of code.  Next week we'll get a little more complicated and write a number guessing game.  The program will pick a number and the user will try to guess it.

Fun Stuff:
Try to do the first four levels of "Human Resource Machine" in the iPad.



 

Comments