Tuesday November 8 th Warm Ups Please find
Tuesday, November 8 th Warm Ups: Please find your new seat! Please NOTICE the personal technology sign is RED. NOTE: if you did NOT present your Finch project yet, we can discuss in the last ten minutes Today … we CONTINUE Python! 1
Programming Computer Screens OFF Fold paper into 1/3 Left side: “Programming Skills I’ve Learned” Middle: “Programs/Projects” Right Side: “Programming skills I still WANT to Learn” 2
Programming Skills I’ve learned Make a list!!! 3
Programming Skills I still WANT to learn Make a list! 4
Let’s fill in our programs/projects 5
Here’s what we are about today … Identify programming skills you’ve learned, skills you want to learn and see the progression between the programming languages we use in class. Define integers, operators, values and expressions and practice these mathematical tools using Python. 6
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 7
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 8
Python Chapter 2 Syntax error programming language 9
Some Simple Math … Your interaction with Python begins with some simple math … Let’s set the stage first … You take notes … 10
Arithmetic Operations & Hierarchy of Operations Operator ** operation Basic expression Exponentiation A ** B * Multiplication A*B / Division A/B + Addition A+B - Subtraction A-B 11
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 12
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 13
Python … 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: (turn on screen and OPEN it!) 14
Let’s test it out … With IDLE open, enter 2+2 What happens? 15
What’s the computer program (Python) really doing? If you wanted to do the same thing in Scratch, how would you do that? 16
In Summary Identify programming skills you’ve learned, skills you want to learn and see the progression between the programming languages we use in class. Define integers, operators, values and expressions and practice these mathematical tools using Python. TOMORROW … You get to PLAY on your own, with a great tutorial. 17
Thursday, November 10 th Warm Up: Please retrieve your questions from yesterday and please get out a pen or pencil Also, please determine exactly where you are in the Python “book” (chapter 3? Chapter 4? ? ? ) Today: Review Python Concepts Continue work 18
Questions from 11/9 1. What’s the difference between an Integer and a floating number? 2. What’s the difference between an Operator and a value? 3. Explain what an Expression is and what it means to evaluate an expression 4. What is Python? 5. How will your knowledge of scratch and finch help you with python? 19
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 20
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 21
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 22
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 23
Using multiple variables >>> fish = 100 >>> bear = 140 >>> fish + bear 240 >>> Fish variable has 100 inside it What does bear represent? 24
Overwriting a variable Replacing the value in a variable with a new value The old value is permanently forgotten 25
Questions to complete 11/10 How do you create a variable in Python? How does that compare to scratch? How do you store a variable in Python? How do you overwrite a variable in Python? What does it mean when Python “evaluates an expression? ” What’s a string? How do you indicate something is a string? 26
Python Chapter 3 27
Friday, November 11 th Warm Up: Take a “Guess” handout from the middle table Read it, analyze what the program is doing Feel free to write all over the paper Let’s review it together … again feel free to write on the code 28
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 29
String Concatenation You can add one string to another >>> 'Hello ' + 'World!' 'Hello World!' >>> 30
Flow of execution creating a set of instructions That is the basic definition of programming 31
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 32
Computers will only do what you tell them Variable names should be relevant to what they are for Variable names are case-sensitive World Worl. D world These are all different variables Capitalize if you use more than one word in variable and no spaces Variable. Name. Multiple. Words 33
Guess Program – flow chart How do you flow chart “while” How do you flow chart “if” 34
Monday, November 14 th Warm Up: Please get out your completed flow chart for the guess program. Today: Review chapter four, questions, chapter 5 – joke program 35
Python Chapter 4 36
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 37
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 38
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 39
Let’s practice Open Python’s IDLE (remember, that’s where you can practice code) In chapter four, turn to pages 6 & 7 Play with the random. randint function!!! 40
Loops are parts of code that will happen (executed) over and over 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 41
Concatenation Review Another example of concatenating strings together print('Well, ' + name + ' I am thinking of a number between 1 and 100. ') string + string 42
43
Comparison Operators < > <= >= == != Less than Greater than Less than or equal to Greater than or equal to Equal to Not equal to 44
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 45
Experiment … pages 11, 12 Booleans, Comparison Operators, Conditions 46
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 47
Now work on Chapter 4 OR if you have completed everything, move on to Chapter 5 There are 6 definitions on my website that you need to complete for chapter four 48
Tuesday, November 15 th Warm Up: Create a flow chart for the joke program 49
Chapter Five Writing Jokes! Complete chapter 5 by writing and running the program Then, complete all the tasks in chapter 5 Then, create your own joke program - include at least three jokes - include user input - show Mrs. H when done both the flow chart and your own joke program Due 11/15 end of class 50
Wednesday, November 16 th Warm Up: Today, you are going to create your own Mad. Lib! Create madlib using Python (all it takes is variables, print and input functions and concatenation) Use these Functions: input & print Create at least 4 Variables Use Concatenation of strings & variables Include the date and time at the beginning of the code import datetime Due at end of class on 11/16 51
Thursday, November 17 th Warm Up: When your python program doesn’t work, how do you fix it? Today Mad Lib Finish reviewing joke programs and flow charts Review Scratch game Chapter 6 Python 52
Monday, April 11 th Warm Up: Please take the chapter six handout from the middle table. Read the code. Write on the document what each line of code does. If you don’t know, circle it. Today: Schedule discussion Brief Overview of chapter six Time to work on chapter six 53
Tuesday, November 29 th Warm Up: It’s time to get back into Python! In your journal, define: Loops, blocks, Boolean Data Type, Comparison Operator (if you can’t remember, you can always look it up in the “book”!) Today: Chapter 6 more to learn! Get a copy of the Dragon program from the middle table 54
Chapter 6 55
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. 56
Functions Define the function BEFORE you call it in the program Let’s look at the choose. Cave function. On what lines is it defined? On what line is it executed or called? 57
Return Value ONLY inside Def blocks Breaks us out of the function (like Break will break out of a while loop) Look at line 17 58
Or Else – always comes after the IF block Explains what happens IF the condition is NOT met Colon : must always accompany the else key word Look at line 32 59
Truth Tables and or not A True False and and and B True False is is is Entire statement True False A True False or or or B True False is is is Entire statement True False not A is not True not False Entire statement is False is True 60
Boolean – Truth tables Look at line 13 It’s an expression with a boolean operator “AND” Which means …. 61
Boolean – Truth tables While The cave is NOT 1 And (since AND is used, both of these conditions must be true for the boolean to be true) The cave is NOT 2 (line 14) Ask the user which cave they want (line 15) The user’s input is the variable “cave” What happens if the user enters “two” or “pig” or “ 17”? 62
Remember I said we would come back to this … Global Scope Variables read outside and inside functions, but can only be modified outside of all functions. Where can we find one in Dragon? Local Scope Variables read or modified inside that function. “forgotten” after the function is executed Where can we find one in Dragon? 63
But …. What do I do if I need to take a global variable and use it inside a function? I have to “give” or “pass” that global variable to the function That’s called a parameter 64
Parameters Line 19 Def check. Cave (chosen. Cave) : Variable names inside parenthesis are called parameters Parameters are local variables that are defined when we call a function chosen. Cave is a new, local, temporary variable It’s the variable that indicates which cave the user selected 65
This is where the game actually begins!!!! 66
It begins … Set variable play. Again to yes Make sure play. Again is yes Run Intro function (which prints several lines) Set a variable, cave. Number, to the results of the choose. Cave function Ask the player if s/he wants to play Again, get player’s input Run check. Cave function, Using the cave. Number Variable, to determine whether or not the user picked the friendly cave 67
Ticket Out Please take out a piece of paper, put your name on it, and answer these questions: 1. What is a global variable? , 2. What is a local variable? 3. What does the time. sleep (2) function do? 4. What’s the proper name for the “ 2” in the time. sleep function above? 5. What does the “ 2” do? ? 6. What does the “return” keyword do (on line 17)in the following function? 68
Wednesday, November 30 th Warm Up: What is the purpose of the def function and why would you use it in a program? 69
Skills to create a program Get with your 8: 00 clock partner Create a new python program, name it practice. py Write python code that accomplishes each of these tasks (work on one of them at a time): NOTE: DO NOT USE the def function!!!!! NOTE: start a NEW program User chooses from a list of options Different programming based on the user’s choice 70
More Skills to Create a Program Create random variable Uses boolean operator to compare two variables and take some action Allows user to choose ‘Play again” 71
Next Steps Share python program with your partner Decide what program you would like to create for your assessment Create a flow chart of the program 72
Thursday, December 1 st Warm Up: SIT BY SAME PARTNER FROM YESTERDAY Did you complete the first two tasks? User chooses from a list of options Different programming based on the user’s choice Which one have you struggled with the most? 73
User chooses from a list of options Different programming based on the user’s choice Create a variable and set it equal to a random number Uses boolean operator to compare two variables and take some action Allows user to choose ‘Play again” 74
Friday, December 2 nd Warm Up: Video Today: Create a flow chart for a Python program you will make 75
What’s a 4? ? Program is professional in quality and ready for publication. Program has a clear purpose, and a clear ending. The program involves the user. The program has a logical ending or allows the user to “play again”. Expertise in PYTHON is demonstrated. This program is a cut above the rest – clearly demonstrating knowledge and expertise using PYTHON. 76
To Do Create flow chart – show it to Mrs. H for approval Begin work on your program Due: Wednesday 12/7 77
Wednesday, December 7 th Warm Up: Write in your journal three things you learned from Mrs. Houtman’s presentation Today: Create a program in Python Show off your Python skills … check the rubric to make sure your program is a “ 4” Due Thursday, December 8 th NOTE: I’m still missing some flow charts! 78
Thursday, December 8 th USE THIS ENTIRE CLASS PERIOD TO PERFECT YOUR PYTHON PROGRAM Friday: Peer Review, turn in program 79
Friday, December 9 th Warm Up: Please take a peer review rubric from the table and then open your Python program Field Trip reminders Conduct peer review with your 3: 00 clock partner – no partner, meet at middle table and find someone 80
Turn in your game Save your file using the proper name: hour_lastname_firstname_python CLOSE THE FILE Go to : www. dropitto. me/hasseld Password = hasseld Doesn’t ask for password? You are not on the proper site! Upload the file when done THEN TURN IN THE PEER REVIEW IN MY BOX! 81
Wednesday, December 14 th Warm Up: Please have your documentation from Javascript up so Mrs. H can check it in – even if you didn’t complete it, I want to see what you did get done Today: review guide for Python quiz – quiz on Friday 82
- Slides: 82