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

agenda
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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

slide-2
SLIDE 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?
slide-3
SLIDE 3

Three pancakes in a two-cake pan…

  • Number of cakes in the

system

– First 5 minutes

  • Number of cakes in the

system

– Second 5 minutes

A B C

B' A C

slide-4
SLIDE 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

slide-5
SLIDE 5

Variables & Types

We use these python types:

  • integer
  • float
  • string
  • boolean

1/14/2013 CompSci101 Peter Lorensen 5

When you start doing something with the variables it becomes interesting.

Examples: age = 16 salary = 277.95 name = “Lorensen” is21 = True

slide-6
SLIDE 6

Python Arithmetic Operators

1/14/2013 CompSci101 Peter Lorensen 6

Oper ator Description Example: a is 10 b is 20 + Addition - Adds values on either side of the

  • perator

a + b will give 30

  • Subtraction - Subtracts right hand operand from

left hand operand a - b will give -10 * Multiplication - Multiplies values on either side

  • f the operator

a * b will give 200 / Division - Divides left hand operand by right hand operand b / a will give 2 % Modulus - Divides left hand operand by right hand operand and returns remainder b % a will give 0 ** Exponent - Performs exponential (power) calculation on operators a**b will give 10 to the power 20

slide-7
SLIDE 7

Python Comparison operators

1/14/2013 CompSci101 Peter Lorensen 7

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

  • perand, if yes then condition becomes true.

(a < b) is true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (a >= b) is not true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (a <= b) is true.

slide-8
SLIDE 8

Python Assignment operators

1/14/2013 CompSci101 Peter Lorensen 8

Operator Description Example = Simple assignment operator, Assigns values from right side

  • perands to left side operand

c = a + b will assigne value of a + b into c += Add AND assignment operator, It adds right operand to the left

  • perand and assign the result to

left operand c += a is equivalent to c = c + a

  • =

Subtract AND assignment

  • perator, It subtracts right
  • perand from the left operand

and assign the result to left

  • perand

c -= a is equivalent to c = c - a

slide-9
SLIDE 9

Python Logical operators

1/14/2013 CompSci101 Peter Lorensen 9

Operat

  • r

Description Example and Called Logical AND operator. If both the operands are true then then condition becomes true. (a and b) is true.

  • r

Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. (a or b) is true. not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. not(a and b) is false.

slide-10
SLIDE 10

Operator precedence

1/14/2013 CompSci101 Peter Lorensen 10

Operator Description ** Exponentiation (raise to the power) * / % Multiply, divide, modulo + - Addition and subtraction <= < > >= Comparison operators <> == != Equality operators = %= /= //= -= += *= **= Assignment operators not or and Logical operators

slide-11
SLIDE 11

How Python executes a function call

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

Function definition Variables: x: 7 square(3 + 4)

University of Washington, Mike Ernst, 2013

def square(x): return x * x Current expression: 1 + square(3 + 4) 1 + square(7) 1 + 49 50 return x * x return 7 * x return 7 * 7 return 49

evaluate this expression

Formal parameter (a variable) Actual argument