Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMSC 120: Visualizing Information 3/25/08

Similar presentations


Presentation on theme: "CMSC 120: Visualizing Information 3/25/08"— Presentation transcript:

1 CMSC 120: Visualizing Information 3/25/08
Conditions CMSC 120: Visualizing Information 3/25/08

2 Control Flow Gotos: jump to different part of program Loops:
GOTO LINE 12 Functions Loops: repetition for-statements while-statements Conditionals

3 Repetition is a Key Concept
World Population in 10 years Repeatedly compute values for successive years Add increase in population to prior population ten times for year in range(10): population = population * (1 + growthRate)

4 Another Way… year = 0 while year < 10:
population = population * (1 + growthRate) year = year + 1

5 While-Statement while <a condition is true>: <do something> Condition is tested and if it is True, then the body of the loop is executed. The condition is tested again and as long as it remains True, then the loop will continue to repeat.

6 Loop Statements for while Index variable: year
while year < 10: p = p * (1 + gR) year = year + 1 for year in range(10): p = p * (1 + gR) Index variable: year Initial value, step size, and stop value determined in for-statement Always runs 10 times Index variable: year Initial value, step size, and stop value determined on different lines Does not have to run 10 times

7 Fixed Number of Repetitions
# do something N times for step in range(N): do something...

8 Limited Duratoin # do something for some duration
while <waiting for condition>: do something... value = <initialState> while value < finalState:

9 Forever # do something forever while True: do something...

10 Conditions Booleans: True, False
In Python: False, None, 0, 0.0, and empty strings and lists are interpreted as false. All other values are true. Special Operators: logical and relational

11 Relational Operators < less than <= less than or equal to
> greater than >= greater than or equal to == equal to != not equal to 42 < 33 12 <= 23 42 > 33 12 >= 33 42 == 33 42 != 33

12 Relational Operators >>> a, b, c = 10, 20, 10 >>> a == b >>> a == c >>> a == a >>> True == 1 >>> False == 1

13 Relational Operators >>> ‘Hello’ == ‘Good Bye’ False >>> ‘Elmore’ < ‘Elvis’ True >>> ‘a’ < ‘A’

14 Relational Operators And Or Not


Download ppt "CMSC 120: Visualizing Information 3/25/08"

Similar presentations


Ads by Google