Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Playful Introduction to Programming by Jason R. Briggs

Similar presentations


Presentation on theme: "A Playful Introduction to Programming by Jason R. Briggs"— Presentation transcript:

1 A Playful Introduction to Programming by Jason R. Briggs
Python for Kids A Playful Introduction to Programming by Jason R. Briggs

2 Computers and Programs
A computer is a machine that stores data. A program is a set of instructions that tells a computer what to do with the data.

3 Why Learn to Program? Makes you a clever user of computers It's fun!
You make stuff (programs) that do things Helps you learn problem solving skills Programmers get jobs

4 Why Learn Python? The Python programming language is aimed at beginners It's easy to learn and use Powerful Lots of program libraries Free Runs on everything Lots of users; lots of help online Used in the real world

5 Some Companies that Use Python

6 Starting Python There are two different types of Python windows
The Shell – where you run Python commands. These commands are NOT saved as a program IDLE – a Python editor This is the window you type in your program. When you run your program, the results will appear in the shell.

7 How to Tell if it’s IDLE or the Shell
Look at the title bar to see which type of window you are in. The Shell window has the word “Shell” The IDLE window will either say Untitled or have the name of your program

8 Start IDLE (a Python editor) (on Windows 10)

9 Inside IDLE I typed help() and <enter> to start "help"
I typed quit to leave "help" but still be in the shell

10 Print() The print() function is used to print out the characters within the parentheses. The message must be in either double quotes, “ “, or single quotes, ‘ ‘ -- You cannot mix the quotes, they both have to be the same.

11 Simple Program Bring up an IDLE window.
On the Shell window, click File  New File

12 Name Your Program Program names need to be meaningful.
Bad program name: stuff Save this program as: first_program.py Python programs end with the extension .py

13 Type the following - EXACTLY
print "Hello World!" print "Hello Again" print "I like typing this." print "This is fun." print 'Yay! Printing.‘ And save your program! Often!!!

14 Running Your Program To run your program, click Run  Run Module

15 Output Your output will show up in the shell. Hello World! Hello Again I like typing this. This is fun. Yay! Printing.

16 Add a line Add another line to your program. Save the program.
Run the program.

17 Pound Sign (hashtag) Put a ‘#’ character at the beginning of a line – any line will do. Save the program Run the program What did the ‘#’ character do?

18 Comments Comments are very important!
Comments tell you what something does in regular English. Comments allow others to easily see what a program does The comment character ‘#’ can be used to disable sections of code.

19 How to Use Comments # A comment, this is so you can read your program later. # Anything after the # is ignored by python. print ("I can have code.”) # and comments after are ignored # You can also use a comment to "disable" or comment out a # piece of code: # print "This won't run.” print ("This will run.”)

20 Results I can have code. This will run.

21 Variables Variables are a container for storing data values.
They can be stored within the computer’s memory. Then you can reference the value by using the variable Variable Names Variables can be named almost anything Cannot use Python keywords (more on this later) It’s important to chose meaningful names that reflect the variable’s content

22 Calculating with Python
You can use the Python shell as a calculator The asterisk is the symbol for multiplying >>> 10 * 32.5

23 Result For the problem: 10 * 32.5 You should have gotten: 325.0

24 Word Problem Calvin paints pictures and sells them at art shows.
He charges $56.25 for a large painting. He charges $25.80 for a small painting. Last month he sold six large paintings and three small paintings. How much did he make in all?

25 Solving >>> 6 * >>> 3 * >>>

26 Another Way to Solve it – Use Variables
>>> a = 6 * >>> b = 3 * >>> a + b 414.9

27 Python Operators The basic symbols used by Python to perform math operations are called operators.

28 More Math to Try Try to figure out the answer before typing it in >>> * 2

29 More Operators % - modulus // floor division ** exponent < less than > Greater than <= less than or equal to <= greater than or equal to

30 Modulus Operator This can be a confusing operator
The modulus operator divides the first number given by the second number given and returns the remainder. It is NOT a plain division problem The modulus operator is useful in determining whether a number is even or odd

31 Modulus Example >>> 10 % 3 >>> 3 % 10 >>> 8 % 2 >>> 45 % 8

32 Results >>> 10 % 3 1 >>> 3 % 10 3 >>> 8 % 2 0 >>> 45 % 8 5 >>>

33 Floor Division // is the floor division operator
It performs just like the / division operator but truncates the results at the decimal point. So instead of seeing an answer like 3.14, you would only get 3


Download ppt "A Playful Introduction to Programming by Jason R. Briggs"

Similar presentations


Ads by Google