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
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/14/2013 CompSci101 Peter Lorensen 1
A B C
B' A C
scale digital computer”
– US Navy: Admiral “It's better to show that
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
1/14/2013 CompSci101 Peter Lorensen 5
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
a + b will give 30
left hand operand a - b will give -10 * Multiplication - Multiplies values on either side
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
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
(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.
1/14/2013 CompSci101 Peter Lorensen 8
Operator Description Example = Simple assignment operator, Assigns values from right side
c = a + b will assigne value of a + b into c += Add AND assignment operator, It adds right operand to the left
left operand c += a is equivalent to c = c + a
Subtract AND assignment
and assign the result to left
c -= a is equivalent to c = c - a
1/14/2013 CompSci101 Peter Lorensen 9
Operat
Description Example and Called Logical AND operator. If both the operands are true then then condition becomes true. (a and b) is true.
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.
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
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