Survey							
                            
		                
		                * Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Wednesday, April 15th
 Warm Up: Please find your new seat! You will need
your spiral notebook and the Python Chapter two
handout
 Today … we begin Python!
1
Why Python?
 Python is a high level language
 It still “hides” much of the technical computer language
 You can use “English” to program
 Dynamic programming language
 Fast and incremental development
 Self checks at run time
2
Why Python
 Expressive Power
 How easy it is to express an idea
 How concisely you can express your idea
 Readability
 Indentation
 Use of words instead of symbols
3
Python
Chapter 2
Syntax error programming language
4
Python begins …
 Python has an “interactive shell” where you can
program a line of code and quickly see whether or not it
works
 It’s an icon on your desktop that looks like this:
5
Python Day One
 You’ll use the Chapter two handout (you must turn it in
every day!!!)
 And the Python interactive shell
 Your job today is to complete chapter two AND to
define the following terms (create a new spot in your
spiral notebook called “PYTHON”):
 Integers and floating numbers
 Expressions and what it means to evaluate an expression
 Values and storing values in variables
 Operators
 Overwriting variables
6
Thursday, April 16th
 Warm Up: Sony’s Security Breach
 Today:
 Highlight Python Chapter Two and Python Chapter Three
7
Arithmetic Operations & Hierarchy of
Operations
Operator
operation
Basic expression
^
Exponentiation
A^B
*
Multiplication
A*B
/
Division
A/B
+
Addition
A+B
-
Subtraction
A-B
8
Examples
Evaluate the following expressions:
x = 3 * 6 - 12 / 3
x = 4 ^ (8 / 4)
y = 12 + 6 / (3 * (10 - 9))
z=5+4^2
m=6/3+3
9
Integers and Floating Point Numbers
Integers = whole numbers 4, 0, 99
Floating point numbers = numbers with decimal point 4.0, 0.0, 23.45
Expressions are made up of values and operators
operator
value
Scratch operators
were the green blocks
value
2+2
expression
10
Python isn’t limited to just numbers.
It’s more than just a fancy calculator.
When a computer solves the expression 10+5 to get the value 15
It has evaluated the expression
10+5 and 10+3+2 both evaluate to 15
5 + is NOT an expression
11
Creating Variables
Variable- Location where memory can be
stored on the computer. Value can change as
the program is running.
 To save the values that our expressions
evaluate to use them later
Used to hold temporary information
Used to control the type of data in calculations
Can store only one piece of data at any time
Data is processed faster
12
Statements
 When you press Enter
 And there is no “error message”
 The instruction has been executed successfully
 The instruction (assignment statement) creates the
variable to be stored
 Statement = not single value
 Expression = single value
13
Create a variable and
evaluate it
 >>> var = 12
create variable
 >>> var
state variable
 12
value stored
 >>> var+6
variable used
 18
variable remembered and
used
 >>>
12+6
is just like var + 6
14
Using multiple variables
 >>> fish = 100
 >>> bear = 140
 >>> fish + bear
 240
 >>>
Fish variable has 100 inside it
What does bear represent?
15
Overwriting a variable
 Replacing the value in a variable
with a new value
 The old value is permanently
forgotten
16
Python
Chapter 3
17
Strings
 Little chunks of text
 To create a string put information between two single
quotes
‘
‘
>>> speak = 'hello'
>>> speak
'hello'
>>>
Strings can have almost any keyboard
character
18
String Concatenation
You can add one string to another
>>> 'Hello ' + 'World!'
'Hello World!'
>>>
19
IDLE = Interactive DeveLopment Environment
Numbers on the left side of the code helps to identify lines
File editor window = space to write code
Different types of instructions will show different colors
Saving = File – save as
name file correctly
Open file = File -- open
Run program = File – Run Module OR F5 (key)
20
IDLE program
print('Hello world!')
print('What is your name?')
myName = input ()
print('It is good to meet you, ' + myName)
Interactive Shell
>>>
Hello world!
What is your name?
Michelle
It is good to meet you, Michelle
>>>
21
Flow of execution
creating a set of instructions
That is the basic definition of programming
22
Comments
# will allow you to add a comment to explain
something that will not interfere with the flow of execution
Function
Mini programs and some are already programmed into
Python code
Print () Print function will display text on screen between ()
Input () Waits for input for the user to enter
Function calls will evaluate a single value --- Return Value
23
Computers will only do what you tell them
Variable names should be relevant to what they are for
Variable names are case-sensitive
World
WorlD
world
These are all different variables
Capitalize if you use more than one word in variable and no spaces
VariableNameMultipleWords
24
Monday, April 20th
 Warm Up: Answer these questions IN WRITING in your
spiral binder
 What’s a string in Python and how does Python
recognize that something is a string?
 What does “string concatenation” mean?
 What is flow of execution and why is it important?
 What is a Function? Name one!
 What are variables?
 Why should you use comments in a program?
25
Go to flow chart ppt
You’ll need paper!
Refresher
26
Flow charts
 Create a flow chart for the “Hello World” program in
chapter three.
 In Closing … WHY are flow charts important? Why are
comments important?
27
Status
What work have you completed in Python???
28
Python
Chapter 4
29
Tuesday, April 21st
 Warm Ups:
 Explain, in your own words, the purpose of flow charts
 Create a flow chart for this scenario:
 I am going to go skiing over Christmas break if there is a lot
of snow and if my kids can go and if the price for this
vacation is less than $1000.
30
START
YES
CAN MY
KIDS GO
SKIING?
IS IT
SNOWING
?
NO
NO
YES
IS THE
PRICE
LESS
THAN
$1000
YES
NO
END
SKI!!!
31
Flow Chart Review
 Always Start and Stop
 Use correct symbols
 Intention: document your program, review and confirm
with customer, write code
 Should be INDEPENDENT of the software
32
Guess Game
 Take a guess game from table
 Look at the code, decide .. What do I already know?
Make notes
 Example: print (‘Hello! What is your name?’)
 This tells Python to print that message on the screen
33
Guess Flow Chart
What does the flow chart look like?
34
We are going to begin to
review each line of code for
Guess and “pick it apart”
35
Import, Module, Function
 Import is a code that tells Python to “bring in” a module
 Function: prewritten code or mini program that you can
use in Python, available in your program
 It’s like boxed spaghetti noodles instead of making them
from scratch
 Examples: print ( ), input ( ),
 Module: prewritten code or mini program used in
Python, you must IMPORT into your program
 It’s like a frozen dinner with spaghetti, noodles and bread
 Example: Random
36
Random Function
number = random.randint(1, 20)
This is a function INSIDE the random
module. This function will return a
random integer between two numbers
Number is a variable that is storing the random number
37
Arguments
Values that are passed to a function when the function is called
Arguments tell the function how to behave
Arguments are separated by commas
38
Let’s practice
 Get with your same partner
 Open Python’s IDLE (remember, that’s where you can
practice code)
 In chapter four, turn to pages 6 & 7
 Play with the random.randit function!!!
39
Now work on Chapter 4
40
Summarize
 In your spiral binder, under summary tab …
 Summarize the following:
 functions
 modules
 Import
 Last, take my quick survey on my web site
 Tomorrow: continue work on Chapter 4 (or go on past
that!) in Python
41
Concatenation Review
Another example of concatenating strings together
print('Well, ' + name + ' I am thinking of a number between 1 and 100.')
string
+ string + string
42
Wednesday, April 22nd
 Warm Ups: Explain, in your own words
 What does the random.randit function do?
 What is the relationship between modules and functions?
 When does a python program terminate? What happens
at that point?
 Today …
 Loops, blocks
 Boolean Data Type
 Comparison Operator
43
Loops
Loops are parts of code that will happen (executed) over and over
Blocks
Blocks begin where the line is indented four spaces
Blocks end where the line indentation is the same as before the block
You must have blocks to create loops
44
45
Comparison Operators
<
>
<=
>=
==
!=
Less than
Greater than
Less than or equal to
Greater than or equal to
Equal to
Not equal to
46
Boolean Data Type
Two values TRUE or FALSE
Case sensitive
Not strings
Also called bools
Conditions
Expression that combines two values with a comparison operator
Always evaluates a Boolean value
47
Experiment … pages
11, 12
Booleans, Comparison Operators, Conditions
48
Booleans, Comparison
Operators, Conditions
 Now … in your summary section of your spiral
notebook summarize these three terms and give an
example of each.
 NO programming until you’re done!
49
Thursday, April 23rd
 Warm Up: Why do you have to indent some
lines of Python code?
 Today …
 Converting strings to integers, Incrementing
Variables, if Statements, BREAK
50
Int( ) function
Converts strings to integers with this function
Break statements
Tells the program to jump out of the while-block
Str( ) function
Converts an integer to a string with this function
51
Tuesday, December 2nd
 Warm Up: Create a flowchart of a joke program you will
create. (See chapter five if you’re confused.) Your joke
program must use at least two escape characters and
must have at least three jokes. When done, create the
joke program. Show Mrs. H when done
52
Chapter 6
53
Friday, May 1st
 Warm Up: Please take out your notes from chapters 5
and 6 and your flow charts
 Today:
 Review some key concepts
 Review your joke program
 Discuss your game for chapter 6
54
Def () function
Def function is creating, or
defining, a new function that
we can call later in our
program. This way you don’t
have to recreate the same
code multiple times.
55
Functions
 Define the function BEFORE you call it in the program
56
Truth Tables
and
or
not
A
True
True
False
False
and
and
and
and
and
B
True
False
True
False
is
is
is
is
is
Entire statement
True
False
False
False
A
True
True
False
False
or
or
or
or
or
B
True
False
True
False
is
is
is
is
is
Entire statement
True
True
True
False
not A is
not True
not False
Entire statement
is
False
is
True
57
Return Value
 ONLY inside Def blocks
 Breaks us out of the function (like Break will break out
of a while loop)
58
Global Scope Variables
read outside and inside functions, but can only be
modified outside of all functions.
Local Scope Variables
read or modified inside that function.
“forgotten” after the function is executed
59
Parameters
 Line 19
 Def checkCave (chosenCave) :
 Variable names inside parenthesis are called
parameters
 Parameters are local variables that are defined when
we call a function
60
Sample program with parameter
Program calls a function we created named sayHello ( )
Then it passes the value in the fizzy variable as an argument
Later the program calls the sayHello ( ) function again, passing the string “Bob”
This is how the program looks when it runs
61
Or Else
 Else – always comes after the IF block
 Explains what happens IF the condition is NOT met
 Colon : must always accompany the else key word
62
JOKE Program
 Let’s check out each other’s joke programs!
 Number off by 8
63
Monday, May 4th
 Warm Up: Go to my website and read the rubric for the
Python Game. Write down any questions you have
about the Python game assignment
 Today –
 Create your game!
64
Game YOU create
 Flow chart
 Comments
 Random function
 Time function
 A function you have created
 Variables
 Comparison operator
65
Python Game – What’s a “4”?
 Clear, accurate, professional flowchart completed.
 Game is professional in quality and ready for
publication.
 Game has a clear purpose, and a clear ending.
 The game involves the user.
 Expertise in PYTHON is demonstrated.
 This game is a cut above the rest – clearly
demonstrating knowledge and expertise using
PYTHON.
66
Thursday, May 7th
 No Warm Up: Focus 100% on game
 Reminder: if I haven’t approved your chapter 5, 6
notes and your two flow charts I will NOT grade
your game!
 See two resources on my website ..
 Due Tomorrow at BEGINNING of class
67
Monday, December 8th
 Warm Up: Please pull up your game. Are you done? If
not, what items need to be completed?
 Chapters 7, 8 Python today
 GAME must be complete at end of class!
68
Tuesday, December 9th
 Warm Up: (see the designated spots) Get into the
following teams:
 1: Eric, Christian, Hailey, Brittney
 2: Austin B, Justin G, Garrett, Ryan E
 3: Logan B, Ryan G, Luke, Tommy
 4: Travis, Stavis, Griffin, Jack
 5: Natalie, Kailey, Trevor, Tomas,
 6: Vish, Kyle, Andrew, Austin M, Josh S
 7: Justin B, Josh J, Mark, Steven
69
As a Team …
 Spend 10 minutes reviewing one another’s games …
 Still not done? That’s OK … you can show what you
have and brainstorm any problems together
70
Individually
 Back to a spot within your team …
 Now it’s time to do one of two things …
 Complete the review of chapters 1 – 6
 All information is in the chapters and based on your
experience
 My PPT slide show is also on the website
 Or
 Complete your game
 NOTE: if you choose option B … then you need to find
some time OUTSIDE CLASS to complete the review
71
Wednesday, December 10th
 Warm up: In pairs (that YOU choose) take ONE
program from the middle table. As a team, decipher
the code. It’s a game. What’s the game about? What
do the blocks of code mean? What do they do?
 Today …
 Complete review for chapters 1 – 6
 Thursday: Review together chapters 1 – 6
 Friday: quiz, chapters 1 - 6
72
Monday, May 11th
 Warm Up: Consider this scenario. My python program
asks the player to choose a random number from 1 –
10. In my program, I take the input and compare it to
the number I randomly generated. The program
doesn’t work. Why not?
 Today:
 Review for quiz – which will be on Wednesday
 Finalize your game and submit it … let’s review what’s
required
73
Game YOU create
 Flow chart
 Comments
 Random function
 Time function
 A function you have created
 Variables
 Comparison operator
74
Python Game – What’s a “4”?
 Clear, accurate, professional flowchart completed.
 Game is professional in quality and ready for
publication.
 Game has a clear purpose, and a clear ending.
 The game involves the user.
 Expertise in PYTHON is demonstrated.
 This game is a cut above the rest – clearly
demonstrating knowledge and expertise using
PYTHON.
75
76
Friday, December 11th
 Warm Up: review for a couple minutes
 Today: QUIZ on Python chapters 1 – 6
 TURN IN PERSONALLY TO ME WHEN DONE
 KEEP TEST ENVIRONMENT
 Time left?
 Top priority – show Mrs. H your game
 Next priority – Hour of Code … see my website
77
Friday, May 8th
 Warm Up: Pull up your Python Game
 Today:
Peer Review
Finish game
Name game properly: lastname_firstname_pythongame
Drop it to me!
www.dropitto.me/hasseld (password = hasseld14)
78