Lecture 2 8/24/18. Computer Memory. Computer Memory. Goals for today. Computer Memory. Computer Memory. Variables Assignment Sequential Steps

Similar documents
Monday, September 28, 2015

Optional: Building a processor from scratch

Week 3. Topic 5 Asymptotes

Overfitting, Model Selection, Cross Validation, Bias-Variance

Lesson 11 Skills Maintenance. Activity 1. Model. The addition problem is = 4. The subtraction problem is 5 9 = 4.

LINEAR PROGRAMMING. Straight line graphs LESSON

Pre-Algebra Notes Unit 8: Graphs and Functions

M O T I O N A N D D R A W I N G

y = f(x) x (x, f(x)) f(x) g(x) = f(x) + 2 (x, g(x)) 0 (0, 1) 1 3 (0, 3) 2 (2, 3) 3 5 (2, 5) 4 (4, 3) 3 5 (4, 5) 5 (5, 5) 5 7 (5, 7)

Wednesday, February 19, 2014

Flux Integrals. Solution. We want to visualize the surface together with the vector field. Here s a picture of exactly that:

Lecture 4 8/24/18. Expressing Procedural Knowledge. Procedural Knowledge. What are we going to cover today? Computational Constructs

Topic 2 Transformations of Functions

2.2 Absolute Value Functions

Introduction to Homogeneous Transformations & Robot Kinematics

Announcements. CSCI 334: Principles of Programming Languages. Lecture 19: C++

Lecture 12 Date:

Algebra I. Linear Equations. Slide 1 / 267 Slide 2 / 267. Slide 3 / 267. Slide 3 (Answer) / 267. Slide 4 / 267. Slide 5 / 267

Section 2.2: Absolute Value Functions, from College Algebra: Corrected Edition by Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a

Lecture 4. Conditionals and Boolean Expressions

SECTION 3-4 Rational Functions

CMSC 425: Lecture 10 Basics of Skeletal Animation and Kinematics

Lecture 2. Variables & Assignment

Properties and Definitions

Exponential Functions. Christopher Thomas

Introduction to Homogeneous Transformations & Robot Kinematics

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Find the Relationship: An Exercise in Graphical Analysis

12.4 The Ellipse. Standard Form of an Ellipse Centered at (0, 0) (0, b) (0, -b) center

Polynomial and Rational Functions

The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development

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

Lesson 12: Sine 5 = 15 3

Determining the 2d transformation that brings one image into alignment (registers it) with another. And

Graphs and Functions

Double Integrals in Polar Coordinates

2.3 Polynomial Functions of Higher Degree with Modeling

PROBLEM SOLVING WITH EXPONENTIAL FUNCTIONS

What are the rules of elementary algebra

Section 4.3 Features of a Line

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

More Coordinate Graphs. How do we find coordinates on the graph?

Using the same procedure that was used in Project 5, enter matrix A and its label into an Excel spreadsheet:

2-1. The Language of Functions. Vocabulary

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

CS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture

Chapter 3 Part 1 Combinational Logic Design

ANGLES See the Math Notes boxes in Lessons and for more information about angle relationships.

Roberto s Notes on Differential Calculus Chapter 8: Graphical analysis Section 5. Graph sketching

Introduction to Trigonometric Functions. Peggy Adamson and Jackie Nicholas

Mini-Lecture 8.1 Introduction to Radicals

Think About. Unit 5 Lesson 3. Investigation. This Situation. Name: a Where do you think the origin of a coordinate system was placed in creating this

Section 1.6: Graphs of Functions, from College Algebra: Corrected Edition by Carl Stitz, Ph.D. and Jeff Zeager, Ph.D. is available under a Creative

Week 10. Topic 1 Polynomial Functions

Systems of Linear Equations

Transformations of Functions. 1. Shifting, reflecting, and stretching graphs Symmetry of functions and equations

Announcements. CS 5565 Network Architecture and Protocols. Count-To-Infinity. Poisoned Reverse. Distance Vector: Link Cost Changes.

4.5.2 The Distance-Vector (DV) Routing Algorithm

angle The figure formed by two lines with a common endpoint called a vertex. angle bisector The line that divides an angle into two equal parts.

Module 2, Section 2 Graphs of Trigonometric Functions

EECS1022 Winter 2018 Additional Notes Tracing Point, PointCollector, and PointCollectorTester

science. In this course we investigate problems both algebraically and graphically.

Variables and Constants

Grade 7/8 Math Circles Fall October 9/10/11 Angles and Light

Bias-Variance Decomposition Error Estimators

Core Connections, Course 3 Checkpoint Materials

Bias-Variance Decomposition Error Estimators Cross-Validation

Modeling with CMU Mini-FEA Program

Graphing Calculator Graphing with the TI-86

Microsoft Access: Table Properites, Complex Forms. Start with a new, blank Access database,

3.9 Differentials. Tangent Line Approximations. Exploration. Using a Tangent Line Approximation

Non-linear models. Basis expansion. Overfitting. Regularization.

Week 27 Algebra 1 Assignment:

Section 3.1: Introduction to Linear Equations in 2 Variables Section 3.2: Graphing by Plotting Points and Finding Intercepts

Connecting Algebra and Geometry with Polygons

Glossary alternate interior angles absolute value function Example alternate exterior angles Example angle of rotation Example

Name Course Days/Start Time

FRANC3D & OSM 3D Tutorial

Boolean Function Simplification

C1M0 Introduction to Maple Assignment Format C1M1 C1M1 Midn John Doe Section 1234 Beginning Maple Syntax any

Test data generation for LRU cache-memory testing

2.3. One-to-One and Inverse Functions. Introduction. Prerequisites. Learning Outcomes

MATH SPEAK - TO BE UNDERSTOOD AND MEMORIZED

Domain of Rational Functions

Overview. Memory Classification Read-Only Memory (ROM) Random Access Memory (RAM) Functional Behavior of RAM. Implementing Static RAM

CMSC 201 Computer Science I for Majors

Laurie s Notes. Overview of Section 6.3

CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

What s the Point? # 2 - Geo Fashion

L3 Rigid Motion Transformations 3.1 Sequences of Transformations Per Date

Chapter 2 Part 5 Combinational Logic Circuits

Algebra I Summer Math Packet

CS559: Computer Graphics

Grade 7/8 Math Circles Fall October 9/10/11 Angles and Light

Implementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)

CS201 - Assignment 8 Due: Wednesday April 23, at the beginning of class

Lecture 3. Input, Output and Data Types

Basics of Java Programming

Excel for Gen Chem General Chemistry Laboratory September 15, 2014

Cross-validation for detecting and preventing overfitting

Transcription:

Goals for toda Lecture 2 Variables Assignment Sequential Steps Sequential Steps, Variables, Assignment Computer Memor If we can t remember things, we can t actuall do ver much Computers have memor the abilit to remember information Computer Memor Computer memor is organied in a hierarch As ou go higher in the hierarch, the memor becomes slower to access, but ou get more, and it is more permanent Offline Memor (e.g. Cloud) Secondar Memor (Files) Main Memor Cache (near CPU) CPU - registers Slower to Access More total data More long-lasting Faster to Access Less total data Less permanent Computer Memor When we sa memor, we ll be referring to main memor Offline Memor (e.g. Cloud) Secondar Memor (Files) Main Memor Cache (near CPU) CPU - registers Slower to Access More total data More long-lasting Faster to Access Less total data Less permanent Computer Memor Later in the course, we ll talk about handling files Offline Memor (e.g. Cloud) Secondar Memor (Files) Main Memor Cache (near CPU) CPU - registers Slower to Access More total data More long-lasting Faster to Access Less total data Less permanent 1

Computer Memor We ll ignore the lowest levels of memor in this class. Offline Memor (e.g. Cloud) Secondar Memor (Files) Main Memor Cache (near CPU) CPU - registers Slower to Access More total data More long-lasting Faster to Access Less total data Less permanent Main Memor Think of main memor as being a bunch of boes that hold information. We will call these boes of memor variables Main Memor Variables and Names The (Pthon) rules for naming A variable (a bo of memor) can hold some unit of information e.g. a number, like the number 19 We need a wa to refer to a particular variable, to distinguish it from the other boes of memor. This will be the variable name. e.g. Think of the name as the label for the bo 19 Names can start with a letter (lowercase or uppercase) or an underscore (_). But, ou generall shouldn t start them with an _ since this tends to impl certain things about the variable. The name can contain letters (lowercase or uppercase), numbers, and underscore characters. The name cannot be a reserved keword These are special commands reserved for the langu itself. The include words like for and while. You will learn these as ou learn to program. Naming Variables and Constants The importance of names So ou could name all our variables to minimie tping e.g. a, b, c, But this would result in confusion later what do these mean? A better wa of thinking about variable (and other) names ou choose in code is to think of communicating with other people You are communicating with anone ou are sharing the code with, including anone who has to take over our code But most importantl to ou, ou are communicating with the future ou the ou that will have forgotten man of the details of the code ou are going back to after doing other things Names help us understand the world, identif particular things, and so on. In computers, the name of a variable distinguishes one particular bo of memor. But, a good name can give more information about the purpose for that piece of memor. Just because a name is valid, doesn t mean it s good. 2

Are these names valid and good? abcde Age m_name M_Name MName 2nd_name name_2nd Winner! F0rTheW1n _densit Gig Em Gig Em Gig-Em Gig_Em Valid but not good (meaningless) Valid and good Valid and good Valid and good (and different from previous) Valid and good (and different from previous) Not valid (starts with a number) Valid, and probabl good Not valid (contains!) Valid, but not good (digits are confusing) Valid, probabl not good (begins with _) Not valid (contains ) Not valid (contains a space) Not valid (contains a -) Valid, but probabl not good (not clear what it contains) More about naming Generall, pick descriptive names Volume might be a better choice than V Not too long, though Volume_of_the_sphere is probabl too long V_sphere, or VolSphere, or Vsphere, etc. might be better names There are a few conventions people use: Constants (that never change) often in ALL_CAPITALS Variables i, j, and k often used for counting or indeing Variables tpicall start with lower-case letters Determining the Variables You Need: Mapping Problems to Software Mapping problems to software representations involves answering a number of questions. What question are ou tring to answer using the software? What are the characteristics of the problem that affect the outcome? How do the affect the outcome and how do the interact? Who is using the software ou re creating? Answers to the second question are likel to help determining what variables our software will have The other questions affect the design and the individual operations Problem Taken from Your Own Life One of the most important skills engineering students need is to be able to effectivel allocate their time to their studies. What questions do we want to answer? How effective are man short, a middle number of medium-length, or a few long stud sessions? How might other aspects of ourselves affect the outcome? What characteristics affect the outcome? The length of stud sessions The number of stud sessions How tired, stressed, hungr, etc. ou are Names for our Stud Session Problem Important concepts/values Time spent studing in a session t advant is it is short, disadvant is it is ambiguous with lots of other concepts time better, but this could be time of starting stud session, time of da, etc. length more accurate, but could be confusing because most often associated with phsical dimensions session_length even better, but what is the units (seconds, minutes, hours) session_length_min good tr, but could be read as the minimum length of a session session_length_minutes prett likel to be understood, of course, it is now a long name Rate of learning concepts/skills concepts_per_minute Number of concepts learned in a session concepts_learned_in_session Writing software requires trade-offs One that will be apparent throughout this course is the trade-off between ease of comprehension and compactness Variable Values When we see a variable name in a program, that is a placeholder for the value contained in that variable s bo of memor. : sa the variable holds value 19. What would be the value of +? + = 19+ = 22 19

Assignment The process of sticking a value into the bo of memor is called assignment. Can assign to an variable new or old When a new value is assigned to a variable, the old value disappears it is replaced b the new one Can (and often does) happen man times for the same variable Assignment statements Pthon assignment statements have the form: <Variable name> = <Value to assign> 19 Assign 0 to 0 Assignment statements Pthon assignment statements have the form: <Variable name> = <Value to assign> The left hand side is the variable name for the bo in memor that will hold the value. Assignment statements Pthon assignment statements have the form: <Variable name> = <Value to assign> The = is the assignment operator. It is NOT the equals sign, though we still often read it aloud as equals. We can read it aloud as gets or is assigned. 19 19 Assignment statements Pthon assignment statements have the form: <Variable name> = <Value to assign> The right hand side of the assignment operator is the value that will be assigned to the bo Assignment statements Pthon assignment statements have the form: <Variable name> = <Value to assign> When this statement is eecuted: We FIRST evaluate the right hand side Then, we assign that value to the left hand side Some eamples follow 19 4

=+1 10 =+1 1. We first find what is the value in variable, which is. 2. Then, we add +1 to get 4.. Then, we assign the value of 4 to variable, replacing the value previousl stored there. 4 =+2* =+2* 1. We first find what is the value in variables and, which are and. 10 2. Then, we multipl 2 times (order of operations!), to get 10.. Then, we add to 10, to get 1 1 4. Then, we assign that value, 1, to variable, replacing the value previousl stored there. =+1 10 =+1 1. We first find what is the value in variable, which is 10. 2. Then, we add 10+1 to get 11.. Then, we assign the value of 11 to variable, replacing the value previousl stored there. 11

=+1 Notice: the use of the same variable on the right and left side is not a problem! While this statement would make no sense if the = reall meant equals, it makes perfect sense since = is actuall an assignment operation. 11 Giving Instructions If ou were asked to give a stranger directions from one place to another, how would ou do it? Drive straight to the net light Turn right Drive 1 mile Take the entrance ramp to the highwa Drive until eit 91 This is a sequence of steps that the person should follow Sequential Steps Sequential Steps We are used to giving and receiving instructions as a sequential series of steps. This is a ver important process learning how to break up a comple task in various was is critical to programming, and to dealing with an large project Including man parts of engineering One of the main was this is done is to create a sequence of steps You ll get some practice with this in lab We are used to giving and receiving instructions as a sequential series of steps. When we give instructions to a computer, we ll do the same thing Our instructions will be a sequence of steps that we want the computer to do We can think of the computer as mindlessl following those instructions, in the order the re specified Later, we will see was of giving instructions that aren t sequential! Assignment sequences Assignment sequences What is the value of at the end? (i.e. what is the value stored in the variable named = = =1 What is the value of at the end? (i.e. what is the value stored in the variable named Net = = =1 It can be helpful to keep track of the instruction pointer that is, what the net instruction to be eecuted is. We can think of the program as being at these points between statements. This starts out in front of the first statement. 6

Assignment sequences Assignment sequences What is the value of at the end? (i.e. what is the value stored in the variable named What is the value of at the end? (i.e. what is the value stored in the variable named Net = = =1 After the first statement is eecuted, the variable has the value stored inside. Net = = =1 After the second statement, has the value. Assignment sequences Assignment sequences (2) Net What is the value of at the end? (i.e. what is the value stored in the variable named = After the third statement, is 1. = =1 1 What is the value of at the end? (i.e. what is the value stored in the variable named = = = =1 Assignment sequences (2) Assignment sequences (2) Net What is the value of at the end? (i.e. what is the value stored in the variable named = = = =1 Net What is the value of at the end? (i.e. what is the value stored in the variable named = = = =1 7

Assignment sequences (2) Assignment sequences (2) Net What is the value of at the end? (i.e. what is the value stored in the variable named = = = =1 Net What is the value of at the end? (i.e. what is the value stored in the variable named = = = =1 Notice that the value of changed, but NOT the value of. The third statement, assigning = was just assigning the current value of to, not making forever equivalent to. 1 Assignment sequences () Assignment sequences () PI.1419 PI PI=.1419 r=. volume=pi*r*r*r*(4/) r Net PI=.1419 r=. volume=pi*r*r*r*(4/) r volume volume Assignment sequences () Assignment sequences ().1419 PI.1419 PI Net PI=.1419 r=. volume=pi*r*r*r*(4/) r. Net PI=.1419 r=. volume=pi*r*r*r*(4/) r. volume 88.977 volume 8

2 =2 = =* =+2 =* =+1 Net =2 = =* =+2 =* =+1 2 4 Net =2 = =* =+2 =* =+1 Net =2 = =* =+2 =* =+1 4 4 Net =2 = =* =+2 =* =+1 Net =2 = =* =+2 =* =+1 20 9

Net =2 = =* =+2 =* =+1 4 21 Special Assignment Operators Certain tpes of operations are ver common. Because of this, some special assignment operators have been defined. = + c Can be written: += c Means, for the variable on the left, increment b the amount on right Similarl for: -=, *=, /=, etc. e.g. a-= means a=a- Assignment sequences () Assignment sequences () 2 =2 = *=4 +=7* =+ -=+1 Net =2 = *=4 +=7* =+ -=+1 Assignment sequences () 2 Assignment sequences () 8 Net =2 = *=4 +=7* =+ -=+1 Net =2 = *=4 +=7* =+ -=+1 The variable gets its prior value,, multiplied b 4. This was equivalent to: =*4 10

Assignment sequences () Assignment sequences () 8 8 Net =2 = *=4 +=7* =+ -=+1 The variable has its value incremented b 7 times the value of, or 6. This was equivalent to: =+7* 9 Net =2 = *=4 +=7* =+ -=+1 9 67 Assignment sequences () A reminder of output Net =2 = *=4 +=7* =+ -=+1 The variable has its value decremented b the value of plus one. This was equivalent to: =-(+1) 8 9-1 Basic output is to the console a window or the screen that shows the output of the program. To show the value of a variable, we print it Command is: print() where is the thing ou want to be printed. The can be: a constant fied value (a literal ) a variable or an epression a combination of literals, constants, variables, functions, etc. that compute to a single value Output Output To print the value of a variable, then, we will write print(), where is the variable name. : The following program a = 10 b = 2**4 b -= a c = b//2 print(c) To print the value of a variable, then, we will write print(), where is the variable name. : The following program a = 10 b = 2**4 b -= a c = b//2 print(c) Outputs:???? Outputs: 11

This week s Lab and Assignment Goal is to practice variable manipulation and sequential statements 12