YCL Session 4 Lesson Plan

Size: px
Start display at page:

Download "YCL Session 4 Lesson Plan"

Transcription

1 YCL Session 4 Lesson Plan Summary In this session, students will learn about functions, including the parts that make up a function, how to define and call a function, and how to use variables and expression to build custom drawing functions. Using three code snippets and their Session 2 drawing, they will rework their drawing to use functions. Session Goals! Step through the 3 component of a function: defining, calling, using expressions! Understand related concepts such as capturing values and variable scope! Rework drawing example using functions and expressions Agenda! Concepts: Drawing with Functions (15 min) Code Snippet: grass.py Code Snippet: tree.py Code Snippet: forest.py! Activity: Drawing with Functions (45 min) Instructions Concepts: Drawing with Functions (15 min) The goal of this chapter is to learn how to create our own functions to draw. We don t want to be stuck with just draw_circle commands. We want to be able to define create our own draw_tree or draw_house commands. A function is a block of code that we can call with just one line. Functions give us the ability to write: Clear, easy-to-read code. The ability to reuse code. We have already used functions in week 2. Now we want define our own. Defining a function is like giving a recipe to computer. Once we give the computer a recipe for banana bread, we just have to tell the computer to make banana bread. There s no need to tell it the steps again.

2 To create our own drawing functions we need three things, most of which which we learned last week: 1. How to define a function 2. How to use variables 3. How to create simple mathematical expressions How to Define a Function Defining a function is rather easy. Start with the keyword def, which is short for define. Next, give the function a name. There are rules for function names, which you might remember from last week. They must: Start with a lowercase letter. After the first letter, only use letters, numbers, and underscores. Spaces are not allowed. Use underscores instead. While upper-case letters can be used, function names are normally all lower-case. After that, we have a set of parenthesis. Inside the parenthesis will go parameters. We ll explain those in a bit. Next, a colon. Everything that is part of the function will be indented four spaces. Usually we start a function with a multi-line comment that explains what the function does.

3 Here is an example of a function: def draw_grass(): This function draws the grass. arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.bitter_lime) Calling a Function To call the function, all we need to do is: draw_grass() Below is a full program that defines and uses the function. Notice that function definitions go below the import statements, and above the rest of the program. While you can put them somewhere else, you shouldn t. Code Snippet: grass.py This is a sample program to show how to draw using functions import arcade def draw_grass(): This function draws the grass. arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.bitter_lime) arcade.open_window(800, 600, "Drawing with Functions") arcade.set_background_color(arcade.color.air_superiority_blue) arcade.start_render() # Call our function to draw the grass draw_grass() arcade.finish_render() arcade.run()

4 Great! Let s make this scene a little better. I ve created another function called draw_pine_tree which will...you guessed it. Draw a pine tree. Here s what that looks like: And here s what the code looks like: Code Snippet: tree.py This is a sample program to show how to draw using functions import arcade def draw_grass(): This function draws the grass. arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.bitter_lime) def draw_pine_tree():

5 This function draws a pine tree. # Draw the trunk arcade.draw_rectangle_filled(100, 200, 30, 80, arcade.color.brown) # Draw three levels of triangles arcade.draw_triangle_filled(50, 215, 150, 215, 100, 320, arcade.color.forest_green) arcade.draw_triangle_filled(50, 255, 150, 255, 100, 360, arcade.color.forest_green) arcade.draw_triangle_filled(60, 295, 140, 295, 100, 400, arcade.color.forest_green) arcade.open_window(800, 600, "Drawing with Functions") arcade.set_background_color(arcade.color.air_superiority_blue) arcade.start_render() # Draw our pretty landscape draw_grass() draw_pine_tree() arcade.finish_render() arcade.run() Great! But what if I want a forest? I want lots of trees? Do I create a function for every tree? That s no fun. How can I create a function that allows me to say where I want the tree? Like what if I wanted to draw three trees and specify (x, y) coordinates of those trees: draw_pine_tree(45, 92) draw_pint_tree(220, 95) draw_pint_tree(250, 90) To be able to do this, I need to learn about variables, expressions, and function parameters. How to Use Variables and Expressions in a Function We can use expressions like the ones we wrote into our calculators last week, even in the calls that we make. For example, we have a draw_triangle_filled function. It takes three points to draw a triangle. It needs x1, y1, x2, y2, x3, y3. What if we wanted to center a triangle around a point, and specify a width and height?

6 We can use that math when we call our function to draw: center_x = 200 center_y = 200 width = 30 height = 30 arcade.draw_triangle_filled(center_x - width / 2, center_y - width / 2, center_x + width / 2, center_y - width / 2, center_x, center_y + width / 2, arcade.color.forest_green) Attention: Order of Operations aka PEMDAS apply here! Python will evaluate expressions using the same order of operations that are expected in standard mathematical expressions. For example this equation does not correctly calculate the average: average = / 5 The first operation done is 98/5. By using parentheses this problem can be fixed: average = ( ) / 5

7 How to Create a Custom Drawing Function We can call functions with parameters. When we declare a function we can put new variables between the parenthesis. See line 15 below. The two variables position_x and position_y will take whatever value is passed in when the function is called. On line 46, we call draw_pine_tree with two numbers, 70 and 90. The variable position_x will be assigned 70, and the variable position_y will be assigned 90. We can use the variables from the parameters, and some mathematical expressions to draw a tree. Line 38 draws a small red point where the origin of the tree is. That is, draws the point at (position_x, position_y). From there you can get an idea of how the other shapes relate in position. Spend some time matching the math to the origin and how it gets there. We can use the function several times as shown below: Code snippet: forest.py

8 1. """ 2. This is a sample program to show how to draw using functions 3. """ import arcade def draw_grass(): 9. """ 10. This function draws the grass. 11. """ 12. arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.bitter_lime) def draw_pine_tree(position_x, position_y): 16. """ 17. This function draws a pine tree. 18. """ # Draw the trunk 21. arcade.draw_rectangle_filled(position_x, position_y + 30, 30, 60, arcade.color.brown) # Draw three levels of triangles 24. arcade.draw_triangle_filled(position_x - 70, position_y + 60, 25. position_x + 70, position_y + 60, 26. position_x, position_y + 150, 27. arcade.color.forest_green) 28. arcade.draw_triangle_filled(position_x - 70, position_y + 100, 29. position_x + 70, position_y + 100, 30. position_x, position_y + 190, 31. arcade.color.forest_green) 32. arcade.draw_triangle_filled(position_x - 55, position_y + 150, 33. position_x + 55, position_y + 150, 34. position_x, position_y + 230, 35. arcade.color.forest_green) # Draw the origin point, just for reference.

9 38. arcade.draw_point(position_x, position_y, arcade.color.red, 4) arcade.open_window(800, 600, "Drawing with Functions") 41. arcade.set_background_color(arcade.color.air_superiority_blue) 42.arcade.start_render() # Draw our pretty landscape 46.draw_grass() 47. draw_pine_tree(70, 90) 48.draw_pine_tree(150, 200) 49.draw_pine_tree(320, 180) 50.draw_pine_tree(520, 190) 51. draw_pine_tree(750, 80) arcade.finish_render() 54.arcade.run()

10 Returning and Capturing Values Functions can not only take in values, functions can also return values. For example: Function that returns two numbers added together # Add two numbers and return the results def sum_two_numbers(a, b): result = a + b return result Note: Return is not a function, and does not use parentheses. Don t doreturn(result). This only gets us halfway there. Because if we call the function now, not much happens. The numbers get added. They get returned to us. But we do nothing with the result. # This doesn't do much, because we don't capture the result sum_two_numbers(22, 15) Capturing Returned Values We need to capture the result. We do that by setting a variable equal to the value the function returned: # Store the function's result into a variable at the bottom of your code my_result = sum_two_numbers(22, 15) print(my_result) Now the result isn t lost. It is stored in my_result which we can print or use some other way. Volume Cylinder Example Function that returns the volume of a cylinder def volume_cylinder(radius, height): pi = volume = pi * radius ** 2 * height return volume Because of the return, this function could be used later on as part of an equation to calculate the volume of a six-pack like this: six_pack_volume = volume_cylinder(2.5, 5) * 6 The value returned from volume_cylinder goes into the equation and is multiplied by six. There is a big difference between a function that prints a value and a function that returns a value. Look at the code below and try it out.

11 # Function that prints the result def sum_print(a, b): result = a + b print(result) # Function that returns the results def sum_return(a, b): result = a + b return result # This prints the sum of 4+4 sum_print(4, 4) # This does not sum_return(4, 4) # This will not set x1 to the sum # It actually gets a value of 'None' because we can store the result of a print function into a variable x1 = sum_print(4, 4) # This will x2 = sum_return(4, 4) When first working with functions it is not unusual to get stuck looking at code like this: def calculate_average(a, b): """ Calculate an average of two numbers result = (a + b) / 2 return result x = 45 y = 56 # Wait, how do I print the result of this? calculate_average(x, y) How do we print the result of calculate_average? The program can t print result because that variable only exists inside the function. We can t just write print(result) at the end of our code, because that variable was created inside the function and cannot be used outside of it. instead, if we capture the result into a variable outside the function, we can print that variable for everyone to see. Instead, use a variable to capture the result:

12 def calculate_average(a, b): """ Calculate an average of two numbers result = (a + b) / 2 return result x = 45 y = 56 average = calculate_average(x, y) print(average) Attention Variable Scope The use of functions introduces the concept of scope. Scope is where in the code a variable is alive and can be accessed. For example, look at the code below: # Define a simple function that sets # x equal to 22 def f(): x = 22 # Call the function f() # This fails, x only exists in f() print(x) The last line will generate an error because x only exists inside of the f() function. The variable is created when f() is called and the memory it uses is freed as soon as f()finishes. Here s where it gets complicated. A more confusing rule is accessing variables created outside of the f() function. In the following code, x is created before the f()function, and thus can be read from inside the f() function. # Create the x variable and set to 44 x = 44 # Define a simple function that prints x def f(): print(x) # Call the function f() Variables created ahead of a function may be read inside of the function only if the function does not change the value. This code, very similar to the code above, will fail. The computer will claim it doesn t know what x is.

13 # Create the x variable and set to 44 x = 44 # Define a simple function that prints x def f(): x += 1 print(x) # Call the function f() Other languages have more complex rules around the creation of variables and scope than Python does. This is part of what makes Python a good introductory language! Make Everything a Function Code is easier to maintain and visualize if it is broken down into parts. Now that we know how to use functions, it is better programming practice to put everything into a function. Below is the same program we had before, but the main code has been moved into a main function. 1. """ 2. This is a sample program to show how to draw using functions 3. """ import arcade def draw_grass(): 9. """ 10. This function draws the grass. 11. """ 12. arcade.draw_lrtb_rectangle_filled(0, 800, 200, 0, arcade.color.bitter_lime) def draw_pine_tree(position_x, position_y): 16. """ 17. This function draws a pine tree. 18. """ 19.

14 20. # Draw the trunk 21. arcade.draw_rectangle_filled(position_x, position_y + 30, 30, 60, arcade.color.brown) # Draw three levels of triangles 24. arcade.draw_triangle_filled(position_x - 70, position_y + 60, 25. position_x + 70, position_y + 60, 26. position_x, position_y + 150, 27. arcade.color.forest_green) 28. arcade.draw_triangle_filled(position_x - 70, position_y + 100, 29. position_x + 70, position_y + 100, 30. position_x, position_y + 190, 31. arcade.color.forest_green) 32. arcade.draw_triangle_filled(position_x - 55, position_y + 150, 33. position_x + 55, position_y + 150, 34. position_x, position_y + 230, 35. arcade.color.forest_green) # Draw the origin point, just for reference. 38. arcade.draw_point(position_x, position_y, arcade.color.red, 4) def main(): 42. """ 43. This is the main function that we call to run our program. 44. """ 45. arcade.open_window(800, 600, "Drawing with Functions") 46. arcade.set_background_color(arcade.color.air_superiority_blue) 47. arcade.start_render() # Draw our pretty landscape 50. draw_grass() 51. draw_pine_tree(70, 90) 52. draw_pine_tree(150, 200) 53. draw_pine_tree(320, 180) 54. draw_pine_tree(520, 190) 55. draw_pine_tree(750, 80) 56.

15 57. arcade.finish_render() 58. arcade.run() # Call the main function to get the program started. 61.if name == " main ": 62. main() Activity: Drawing With Functions (45 min) As outlined below, it may be easiest for students to start by combining the drawings they created in Session 2 with the code snippets they step through in the lecture, tree.py and forest.py, than to start from scratch. Instructions:! Start with the same PyCharm project you used for previous sessions. Create a new directory for Session 4. Make sure it is not inside of the folders for Sessions 1, 2, or 3. Feel free to use any code from previous weeks you want, just copy it across. It may be easiest to rework your drawing_picture.py to use functions.! Put any code you will need in a new file under Session 4, called functions.py! HINT: Instead of calling a certain shape-drawing function already built for you with coordinates, start with a coordinate x, a coordinate y, and tell it the line how far to extend. See the tree.py, grass.py, and forest.py code snippets for reference.! If you want to start from scratch: Create three functions that draw something. Define the function and successfully call it. Make your drawing function complex. Try not to copy from earlier examples, and have multiple lines in your function definition. Pass in x and y parameters and successfully position the object. BONUS: put everything into a main() function as exemplified at the end of the lesson.

Using IDLE for

Using IDLE for Using IDLE for 15-110 Step 1: Installing Python Download and install Python using the Resources page of the 15-110 website. Be sure to install version 3.3.2 and the correct version depending on whether

More information

Intro to Python Programming

Intro to Python Programming Intro to Python Programming If you re using chromebooks at your school, you can use an online editor called Trinket to code in Python, and you ll have an online portfolio of your projects which you can

More information

[ the academy_of_code] Senior Beginners

[ the academy_of_code] Senior Beginners [ the academy_of_code] Senior Beginners 1 Drawing Circles First step open Processing Open Processing by clicking on the Processing icon (that s the white P on the blue background your teacher will tell

More information

Adding content to your Blackboard 9.1 class

Adding content to your Blackboard 9.1 class Adding content to your Blackboard 9.1 class There are quite a few options listed when you click the Build Content button in your class, but you ll probably only use a couple of them most of the time. Note

More information

Programming with Python

Programming with Python Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2

More information

Boolean Expressions. Is Equal and Is Not Equal

Boolean Expressions. Is Equal and Is Not Equal 3 MAKING CHOICES Now that we ve covered how to create constants and variables, you re ready to learn how to tell your computer to make choices. This chapter is about controlling the flow of a computer

More information

Watkins Mill High School. Algebra 2. Math Challenge

Watkins Mill High School. Algebra 2. Math Challenge Watkins Mill High School Algebra 2 Math Challenge "This packet will help you prepare for Algebra 2 next fall. It will be collected the first week of school. It will count as a grade in the first marking

More information

Boolean Expressions. Is Equal and Is Not Equal

Boolean Expressions. Is Equal and Is Not Equal 3 MAKING CHOICES ow that we ve covered how to create constants and variables, you re ready to learn how to tell your computer to make choices. This chapter is about controlling the flow of a computer program

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions.

Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions. 1.0 Expressions Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions. Numbers are examples of primitive expressions, meaning

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Part 1 Arithmetic Operator Precedence

Part 1 Arithmetic Operator Precedence California State University, Sacramento College of Engineering and Computer Science Computer Science 10: Introduction to Programming Logic Activity C Expressions Computers were originally designed for

More information

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #11 Procedural Composition and Abstraction. c 2005, 2004 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #11 Procedural Composition and Abstraction c 2005, 2004 Jason Zych 1 Lecture 11 : Procedural Composition and Abstraction Solving a problem...with

More information

Chapter 7. Polygons, Circles, Stars and Stuff

Chapter 7. Polygons, Circles, Stars and Stuff Chapter 7. Polygons, Circles, Stars and Stuff Now it s time for the magic! Magic? asked Morf. What do you mean, magic? You ve never talked about Logo magic before. We ve talked about shapes, and how you

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Customizing DAZ Studio

Customizing DAZ Studio Customizing DAZ Studio This tutorial covers from the beginning customization options such as setting tabs to the more advanced options such as setting hot keys and altering the menu layout. Introduction:

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics Assignment 1: Turtle Graphics Page 1 600.112: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics Peter H. Fröhlich phf@cs.jhu.edu Joanne Selinski joanne@cs.jhu.edu Due Date: Wednesdays

More information

Semester 2, 2018: Lab 1

Semester 2, 2018: Lab 1 Semester 2, 2018: Lab 1 S2 2018 Lab 1 This lab has two parts. Part A is intended to help you familiarise yourself with the computing environment found on the CSIT lab computers which you will be using

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

Part 6b: The effect of scale on raster calculations mean local relief and slope

Part 6b: The effect of scale on raster calculations mean local relief and slope Part 6b: The effect of scale on raster calculations mean local relief and slope Due: Be done with this section by class on Monday 10 Oct. Tasks: Calculate slope for three rasters and produce a decent looking

More information

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and

More information

roboturtle Documentation

roboturtle Documentation roboturtle Documentation Release 0.1 Nicholas A. Del Grosso November 28, 2016 Contents 1 Micro-Workshop 1: Introduction to Python with Turtle Graphics 3 1.1 Workshop Description..........................................

More information

Functions Structure and Parameters behind the scenes with diagrams!

Functions Structure and Parameters behind the scenes with diagrams! Functions Structure and Parameters behind the scenes with diagrams! Congratulations! You're now in week 2, diving deeper into programming and its essential components. In this case, we will talk about

More information

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Variable is a letter or symbol that represents a number. Variable (algebraic)

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

4. Java Project Design, Input Methods

4. Java Project Design, Input Methods 4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

More information

T H E I N T E R A C T I V E S H E L L

T H E I N T E R A C T I V E S H E L L 3 T H E I N T E R A C T I V E S H E L L The Analytical Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform. Ada Lovelace, October 1842 Before

More information

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay. Welcome Back! Now that we ve covered the basics on how to use templates and how to customise them, it s time to learn some more advanced techniques that will help you create outstanding ebay listings!

More information

Grade 6 Math Circles October 16 & Non-Euclidean Geometry and the Globe

Grade 6 Math Circles October 16 & Non-Euclidean Geometry and the Globe Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Grade 6 Math Circles October 16 & 17 2018 Non-Euclidean Geometry and the Globe (Euclidean) Geometry Review:

More information

Week 1: Introduction to R, part 1

Week 1: Introduction to R, part 1 Week 1: Introduction to R, part 1 Goals Learning how to start with R and RStudio Use the command line Use functions in R Learning the Tools What is R? What is RStudio? Getting started R is a computer program

More information

CMSC 201 Computer Science I for Majors

CMSC 201 Computer Science I for Majors CMSC 201 Computer Science I for Majors Lecture 02 Intro to Python Syllabus Last Class We Covered Grading scheme Academic Integrity Policy (Collaboration Policy) Getting Help Office hours Programming Mindset

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

Shorthand for values: variables

Shorthand for values: variables Chapter 2 Shorthand for values: variables 2.1 Defining a variable You ve typed a lot of expressions into the computer involving pictures, but every time you need a different picture, you ve needed to find

More information

9 R1 Get another piece of paper. We re going to have fun keeping track of (inaudible). Um How much time do you have? Are you getting tired?

9 R1 Get another piece of paper. We re going to have fun keeping track of (inaudible). Um How much time do you have? Are you getting tired? Page: 1 of 14 1 R1 And this is tell me what this is? 2 Stephanie x times y plus x times y or hm? 3 R1 What are you thinking? 4 Stephanie I don t know. 5 R1 Tell me what you re thinking. 6 Stephanie Well.

More information

MITOCW ocw f99-lec12_300k

MITOCW ocw f99-lec12_300k MITOCW ocw-18.06-f99-lec12_300k This is lecture twelve. OK. We've reached twelve lectures. And this one is more than the others about applications of linear algebra. And I'll confess. When I'm giving you

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block

THE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block THE IF STATEMENT The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), elsewe process another block of statements (called the else-block).

More information

Honors Computer Science Python Mr. Clausen Program 7A, 7B

Honors Computer Science Python Mr. Clausen Program 7A, 7B Honors Computer Science Python Mr. Clausen Program 7A, 7B PROGRAM 7A Turtle Graphics Animation (100 points) Here is the overview of the program. Use functions to draw a minimum of two background scenes.

More information

Intro. Speed V Growth

Intro. Speed V Growth Intro Good code is two things. It's elegant, and it's fast. In other words, we got a need for speed. We want to find out what's fast, what's slow, and what we can optimize. First, we'll take a tour of

More information

Grade 6 Math Circles October 16 & Non-Euclidean Geometry and the Globe

Grade 6 Math Circles October 16 & Non-Euclidean Geometry and the Globe Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Grade 6 Math Circles October 16 & 17 2018 Non-Euclidean Geometry and the Globe (Euclidean) Geometry Review:

More information

[Video] and so on... Problems that require a function definition can be phrased as a word problem such as the following:

[Video] and so on... Problems that require a function definition can be phrased as a word problem such as the following: Defining Functions (Time 20 minutes) Defining a value is helpful when a program has lots of identical expressions. Sometimes, however, a program has expressions that aren t identical, but are just very

More information

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!

6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week! 6.189 Project 1 Readings Get caught up on all the readings from this week! What to hand in Print out your hangman code and turn it in Monday, Jaunary 10 at 2:10 PM. Be sure to write your name and section

More information

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

3Using and Writing. Functions. Understanding Functions 41. In this chapter, I ll explain what functions are and how to use them.

3Using and Writing. Functions. Understanding Functions 41. In this chapter, I ll explain what functions are and how to use them. 3Using and Writing Functions Understanding Functions 41 Using Methods 42 Writing Custom Functions 46 Understanding Modular Functions 49 Making a Function Modular 50 Making a Function Return a Value 59

More information

CS1 Lecture 5 Jan. 25, 2019

CS1 Lecture 5 Jan. 25, 2019 CS1 Lecture 5 Jan. 25, 2019 HW1 due Monday, 9:00am. Notes: Do not write all the code at once before starting to test. Take tiny steps. Write a few lines test... add a line or two test... add another line

More information

Notebook Assignments

Notebook Assignments Notebook Assignments These six assignments are a notebook using techniques from class in the single concrete context of graph theory. This is supplemental to your usual assignments, and is designed for

More information

SCRATCH MODULE 3: NUMBER CONVERSIONS

SCRATCH MODULE 3: NUMBER CONVERSIONS SCRATCH MODULE 3: NUMBER CONVERSIONS INTRODUCTION The purpose of this module is to experiment with user interactions, error checking input, and number conversion algorithms in Scratch. We will be exploring

More information

Introduction to Programming with JES

Introduction to Programming with JES Introduction to Programming with JES Titus Winters & Josef Spjut October 6, 2005 1 Introduction First off, welcome to UCR, and congratulations on becoming a Computer Engineering major. Excellent choice.

More information

Functions: Decomposition And Code Reuse

Functions: Decomposition And Code Reuse Programming: problem decomposition into functions 1 Functions: Decomposition And Code Reuse This section of notes shows you how to write functions that can be used to: decompose large problems, and to

More information

Python for Non-programmers

Python for Non-programmers Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

More information

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts) Problem 0: Install Eclipse + CDT (or, as an alternative, Netbeans). Follow the instructions on my web site.

More information

Chapter 1 Section 1 Lesson: Solving Linear Equations

Chapter 1 Section 1 Lesson: Solving Linear Equations Introduction Linear equations are the simplest types of equations to solve. In a linear equation, all variables are to the first power only. All linear equations in one variable can be reduced to the form

More information

MITOCW watch?v=se4p7ivcune

MITOCW watch?v=se4p7ivcune MITOCW watch?v=se4p7ivcune The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia The goal for this tutorial is to make sure that you understand a few key concepts related to programming, and that you know the basics

More information

Section 0.3 The Order of Operations

Section 0.3 The Order of Operations Section 0.3 The Contents: Evaluating an Expression Grouping Symbols OPERATIONS The Distributive Property Answers Focus Exercises Let s be reminded of those operations seen thus far in the course: Operation

More information

Class #1. introduction, functions, variables, conditionals

Class #1. introduction, functions, variables, conditionals Class #1 introduction, functions, variables, conditionals what is processing hello world tour of the grounds functions,expressions, statements console/debugging drawing data types and variables decisions

More information

Spectroscopic Analysis: Peak Detector

Spectroscopic Analysis: Peak Detector Electronics and Instrumentation Laboratory Sacramento State Physics Department Spectroscopic Analysis: Peak Detector Purpose: The purpose of this experiment is a common sort of experiment in spectroscopy.

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

INVESTIGATE: PARAMETRIC AND CUSTOMIZABLE MODELS

INVESTIGATE: PARAMETRIC AND CUSTOMIZABLE MODELS LEARNING OBJECTIVES General Confidence writing basic code with simple parameters Understanding measurement and dimensions 3D Design (Parametric Modeling) Modifying parameters Basic OpenSCAD code Translation

More information

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.

Try typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below. Name: Date: Instructions: PYTHON - INTRODUCTORY TASKS Open Idle (the program we will be using to write our Python codes). We can use the following code in Python to work out numeracy calculations. Try

More information

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5

Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 Formal Methods of Software Design, Eric Hehner, segment 1 page 1 out of 5 [talking head] Formal Methods of Software Engineering means the use of mathematics as an aid to writing programs. Before we can

More information

CISC 1600 Lecture 3.1 Introduction to Processing

CISC 1600 Lecture 3.1 Introduction to Processing CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists

More information

CSCI 204 Introduction to Computer Science II. Lab 6: Stack ADT

CSCI 204 Introduction to Computer Science II. Lab 6: Stack ADT CSCI 204 Introduction to Computer Science II 1. Objectives In this lab, you will practice the following: Learn about the Stack ADT Implement the Stack ADT using an array Lab 6: Stack ADT Use a Stack to

More information

Variables, expressions and statements

Variables, expressions and statements Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the

More information

Built-in functions. You ve used several functions already. >>> len("atggtca") 7 >>> abs(-6) 6 >>> float("3.1415") >>>

Built-in functions. You ve used several functions already. >>> len(atggtca) 7 >>> abs(-6) 6 >>> float(3.1415) >>> Functions Built-in functions You ve used several functions already len("atggtca") 7 abs(-6) 6 float("3.1415") 3.1415000000000002 What are functions? A function is a code block with a name def hello():

More information

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122

Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 Foundations, Reasoning About Algorithms, and Design By Contract CMPSC 122 I. Logic 101 In logic, a statement or proposition is a sentence that can either be true or false. A predicate is a sentence in

More information

An Interesting Way to Combine Numbers

An Interesting Way to Combine Numbers An Interesting Way to Combine Numbers Joshua Zucker and Tom Davis October 12, 2016 Abstract This exercise can be used for middle school students and older. The original problem seems almost impossibly

More information

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function Due: Mar25 (Note that this is a 2-week lab) This lab must be done using paired partners. You should choose a different partner

More information

Skill 1: Multiplying Polynomials

Skill 1: Multiplying Polynomials CS103 Spring 2018 Mathematical Prerequisites Although CS103 is primarily a math class, this course does not require any higher math as a prerequisite. The most advanced level of mathematics you'll need

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

Magic Set Editor 2 Template Creation Tutorial

Magic Set Editor 2 Template Creation Tutorial Magic Set Editor 2 Template Creation Tutorial Basics Several types of folders, called packages, must be set up correctly to create any template for MSE. (All files related to MSE template creation are

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Creating a Box-and-Whisker Graph in Excel: Step One: Step Two:

Creating a Box-and-Whisker Graph in Excel: Step One: Step Two: Creating a Box-and-Whisker Graph in Excel: It s not as simple as selecting Box and Whisker from the Chart Wizard. But if you ve made a few graphs in Excel before, it s not that complicated to convince

More information

Solution Guide for Chapter 12

Solution Guide for Chapter 12 Solution Guide for Chapter 1 Here are the solutions for the Doing the Math exercises in Kiss My Math! DTM from p. 170-1. Start with x. Add, then multiply by 4. So, starting with x, when we add, we ll get:

More information

(Refer Slide Time 3:31)

(Refer Slide Time 3:31) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions

More information

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below. Graphing in Excel featuring Excel 2007 1 A spreadsheet can be a powerful tool for analyzing and graphing data, but it works completely differently from the graphing calculator that you re used to. If you

More information

Intro To Excel Spreadsheet for use in Introductory Sciences

Intro To Excel Spreadsheet for use in Introductory Sciences INTRO TO EXCEL SPREADSHEET (World Population) Objectives: Become familiar with the Excel spreadsheet environment. (Parts 1-5) Learn to create and save a worksheet. (Part 1) Perform simple calculations,

More information

Activity Guide - Public Key Cryptography

Activity Guide - Public Key Cryptography Unit 2 Lesson 19 Name(s) Period Date Activity Guide - Public Key Cryptography Introduction This activity is similar to the cups and beans encryption we did in a previous lesson. However, instead of using

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

RECURSION, RECURSION, (TREE) RECURSION! 2

RECURSION, RECURSION, (TREE) RECURSION! 2 RECURSION, RECURSION, (TREE) RECURSION! 2 COMPUTER SCIENCE 61A February 5, 2015 A function is recursive if it calls itself. Below is a recursive factorial function. def factorial(n): if n == 0 or n ==

More information

Chapter 2: Objects, classes and factories

Chapter 2: Objects, classes and factories Chapter 2 Objects, classes and factories By the end of this chapter you will have the essential knowledge to start our big project writing the MyPong application. This chapter is important for another

More information

APPM 2460 Matlab Basics

APPM 2460 Matlab Basics APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on

More information

9. MATHEMATICIANS ARE FOND OF COLLECTIONS

9. MATHEMATICIANS ARE FOND OF COLLECTIONS get the complete book: http://wwwonemathematicalcatorg/getfulltextfullbookhtm 9 MATHEMATICIANS ARE FOND OF COLLECTIONS collections Collections are extremely important in life: when we group together objects

More information

1 Lecture 7: Functions I

1 Lecture 7: Functions I L7 June 18, 2017 1 Lecture 7: Functions I CSCI 1360E: Foundations for Informatics and Analytics 1.1 Overview and Objectives In this lecture, we ll introduce the concept of functions, critical abstractions

More information

TABLE OF CONTENTS. Worksheets Lesson 1 Worksheet Introduction to Geometry 41 Lesson 2 Worksheet Naming Plane and Solid Shapes.. 44

TABLE OF CONTENTS. Worksheets Lesson 1 Worksheet Introduction to Geometry 41 Lesson 2 Worksheet Naming Plane and Solid Shapes.. 44 Acknowledgement: A+ TutorSoft would like to thank all the individuals who helped research, write, develop, edit, and launch our MATH Curriculum products. Countless weeks, years, and months have been devoted

More information

Public Meeting Agenda Formatting Best Practices

Public Meeting Agenda Formatting Best Practices DEFINITIVE GUIDE Public Meeting Agenda Formatting Best Practices In this guide, we will first walk you through some best practices with text and images. Then, we will show you how to execute the best practices

More information

CMSC 201 Fall 2018 Python Coding Standards

CMSC 201 Fall 2018 Python Coding Standards CMSC 201 Fall 2018 Python Coding Standards The purpose of these coding standards is to make programs readable and maintainable. In the real world you may need to update your own code more than 6 months

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

Recall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?

Recall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean? 6.189 Day 4 Readings How To Think Like A Computer Scientist, chapters 7 and 8 6.01 Fall 2009 Course Notes page 27-29 ( Lists and Iterations over lists ; List Comprehensions is optional); sections 3.2-3.4

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Module 02 Lecture - 45 Memoization Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 02 Lecture - 45 Memoization Let us continue our discussion of inductive definitions. (Refer Slide Time: 00:05)

More information

Converting Between Mixed Numbers & Improper Fractions

Converting Between Mixed Numbers & Improper Fractions 01 Converting Between Mixed Numbers & Improper Fractions A mixed number is a whole number and a fraction: 4 1 2 An improper fraction is a fraction with a larger numerator than denominator: 9 2 You can

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

PROBLEM SOLVING 11. July 24, 2012

PROBLEM SOLVING 11. July 24, 2012 PROBLEM SOLVING 11 COMPUTER SCIENCE 61A July 24, 2012 Today s section will be a kind of Meta-Section, we are going to walk through some medium to hard-ish problems in Scheme, and we will discuss some methods

More information