Class Notes (838,950)
Canada (511,158)
CSC108H1 (113)
Lecture

october 12 notes

2 Pages
108 Views
Unlock Document

Department
Computer Science
Course
CSC108H1
Professor
Michelle Craig
Semester
Fall

Description
 Given the variables name1 and name2, write a fragment of code that assigns the larger of their associated values to first. >>> first = max(one, two)  Test covers readings, lecture, lab, assignment  “top-level” code o code that isn’t inside a function definition or guarded by an “if _ _name_ _ == ‘_ _main_ _’:” condition  while loops 1. while : 2. 3. [statement after]  how they work o general format 1. while expression: 2. statements o sounds like; while the expression is true, execute the statements o but really means: if the expression is true, execute the statements one [more] time. Then go back and consider doing it all again o the difference: if the expression becomes false during the statements, it still completes all of them  it doesn’t stop the loop immediately  ex. 1. n = 3 2. while (n > 0): 3. if n % 5 == 0: 4. n = -99 5. print n 6. n = n + 1 7. print „all done‟ output: 3 # go through the first time 4 # go through the second time, n + 1 -99 # go through the third time, n reassigned from 5 to -99 all done #go through the fourth time, n reassigned from -99 to -98  ex. 1. def yes_no_answer(prompt): 2. „‟‟use string prompt to ask the user for a yes/no answer. Continue until 3. they give a valid response. Return True iff the answer was “yes”.‟‟‟ 4. 5.
More Less

Related notes for CSC108H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit