108HL09 - Scope, Namespaces and String Formatting Lecture...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Scope, Namespaces and String Formatting Lecture 9, Week 3 January 28, 2011 CSC108H1S Velian Pandeliev 1 Friday, January 28, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements 2 Quiz Average Was 88.3%. Solutions and rubric will be posted today. Re-mark requests are due a week from today. Assignment 1, Part 6: you should list all factors starting at 1 . This way, every number from 1 to 100 will output at least one number. Friday, January 28, 2011
Background image of page 2
3 Recap of Lecture 8 Friday, January 28, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The while Loop 4 The while loop is the frst oF two loops we will see in Python. It repeatedly perForms the same action as long as a particular condition is met: while boolean_condition : statement1 statement2 ... The condition is checked frst. IF it evaluates to ±alse, the body oF the while statement does not execute. IF it evaluates to True, the body executes. Then, the the condition is checked again. Friday, January 28, 2011
Background image of page 4
The while Loop: Uses 5 There are three main uses for the while loop: 1) To repeat an action forever 2) To repeat an action as many times as is necessary for some condition to be met 3) To repeat an action a set number of times Friday, January 28, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Scope and Namespaces Friday, January 28, 2011
Background image of page 6
Variable Scope 7 What does this program do: def f(): t = 5 print t x = 9 print x f() print t This program results in an error. t is assigned a value in the body of function f() . It's a local variable (local to f() ) and is not available outside the function body of f() . Friday, January 28, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 What does this program do: def f(): t = 5 print x x = 9 print x f() print t In contrast, x is assigned a value outside a function deFnition, making it a global variable . It is available to the main program, and also to any functions inside it. Friday, January 28, 2011
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

108HL09 - Scope, Namespaces and String Formatting Lecture...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online