agenda
play

Agenda APT demo (what is the Green Dance?) Pancakes How to hand-in - PowerPoint PPT Presentation

Agenda APT demo (what is the Green Dance?) Pancakes How to hand-in Types and values in detail Eclipse demo 1/14/2013 CompSci101 Peter Lorensen 1 How to teach pancake flipping http://www.youtube.com/watch?v=W_gxLKSsSIE


  1. Agenda • APT demo (what is the Green Dance?) • Pancakes • How to hand-in • Types and values in detail • Eclipse demo 1/14/2013 CompSci101 Peter Lorensen 1

  2. How to teach pancake flipping • http://www.youtube.com/watch?v=W_gxLKSsSIE – For longer, more complex robotic tasks • http://www.youtube.com/watch?v=4usoE981e7I • Back to specifics: – Capacity = 5 – Numcakes = 1,2,…5? – Numcakes = 6,7,8,9,10? – Numcakes = 11,12,13,14,15? • Is five special? 4? 3? 2?

  3. Three pancakes in a two- cake pan… • Number of cakes in the • Number of cakes in the system system – First 5 minutes – Second 5 minutes B' B C A C A

  4. Grace Murray Hopper (1906-1992) • “ third programmer on world's first large- scale digital computer ” – US Navy: Admiral “ It's better to show that something can be done and apologize for not asking permission, than to try to persuade the powers that be at the beginning ”  ACM Hopper award given for contributions before 35 2004: Jennifer Rexford 2010: Craig Gentry: http://www.youtube.com/watch?v=qe-zmHoPW30 2011: Luis von Ahn

  5. Variables & Types We use these Examples: python types: age = 16 • integer salary = 277.95 • float • string name = “ Lorensen ” • boolean is21 = True When you start doing something with the variables it becomes interesting. 1/14/2013 CompSci101 Peter Lorensen 5

  6. Python Arithmetic Operators Oper Description Example: a is 10 b is 20 ator + Addition - Adds values on either side of the a + b will give 30 operator - Subtraction - Subtracts right hand operand from a - b will give -10 left hand operand * Multiplication - Multiplies values on either side a * b will give 200 of the operator / Division - Divides left hand operand by right b / a will give 2 hand operand % Modulus - Divides left hand operand by right b % a will give 0 hand operand and returns remainder ** Exponent - Performs exponential (power) a**b will give 10 to the power 20 calculation on operators 1/14/2013 CompSci101 Peter Lorensen 6

  7. Python Comparison operators Oper Description Example a is 10 b is 20 ator == Checks if the value of two operands are equal or not, if yes then (a == b) is not true. condition becomes true. != Checks if the value of two operands are equal or not, if values (a != b) is true. are not equal then condition becomes true. <> Checks if the value of two operands are equal or not, if values (a <> b) is true. This is similar to are not equal then condition becomes true. != operator. > Checks if the value of left operand is greater than the value of (a > b) is not true. right operand, if yes then condition becomes true. < Checks if the value of left operand is less than the value of right (a < b) is true. operand, if yes then condition becomes true. >= Checks if the value of left operand is greater than or equal to the (a >= b) is not true. value of right operand, if yes then condition becomes true. <= Checks if the value of left operand is less than or equal to the (a <= b) is true. value of right operand, if yes then condition becomes true. 1/14/2013 CompSci101 Peter Lorensen 7

  8. Python Assignment operators Operator Description Example = Simple assignment operator, c = a + b will assigne value of a + b into c Assigns values from right side operands to left side operand += Add AND assignment operator, It c += a is equivalent to c = c + a adds right operand to the left operand and assign the result to left operand -= Subtract AND assignment c -= a is equivalent to c = c - a operator, It subtracts right operand from the left operand and assign the result to left operand 1/14/2013 CompSci101 Peter Lorensen 8

  9. Python Logical operators Operat Description Example or and Called Logical AND operator. If both (a and b) is true. the operands are true then then condition becomes true. or Called Logical OR Operator. If any of (a or b) is true. the two operands are non zero then then condition becomes true. not Called Logical NOT Operator. Use to not(a and b) is false. reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. 1/14/2013 CompSci101 Peter Lorensen 9

  10. Operator precedence Operator Description ** Exponentiation (raise to the power) * / % Multiply, divide, modulo + - Addition and subtraction <= < > >= Comparison operators <> == != Equality operators = %= /= //= -= += *= **= Assignment operators not or and Logical operators 1/14/2013 CompSci101 Peter Lorensen 10

  11. University of Washington, Mike Ernst, 2013 How Python executes a function call Formal Function def square(x): parameter definition (a variable) return x * x Actual argument Current expression: square(3 + 4) 1 + square(3 + 4) return x * x 1 + square(7) Variables: x: 7 return 7 * x evaluate this expression return 7 * 7 return 49 1 + 49 50 1. Evaluate the argument (at the call site) 2. Assign the formal parameter name to the argument’s value – A new variable, not reuse of any existing variable of the same name 3. Evaluate the statements in the body one by one 4. At a return statement: – Remember the value of the expression – Formal parameter variable disappears – exists only during the call! – The call expression evaluates to the return value

Recommend


More recommend