ITP 115 Lecture Notes - Lecture 5: List Of Coffee Drinks, Infinite Loop, While Loop

48 views3 pages

Document Summary

Outline: while loops, for loops, range() function, strings as sequences, sequence functions and operators. Loop motivation #1: we want to repeat things multiple times, pseudocode. Loop motivation #2: users make mistakes (ideally we should ask them to try again, while. The user has not entered y or n . Ask them to enter y or n . While loops: loops let us repeat something, while loop is similar to the if structure. While condition: statement1 statement2: as long as the condition is true, the block (loop body, which is shown above in. Statement1 statement2 ) is executed: when the condition is false, the loop exits and the program continues. While numbottles >0: print( cold brew coffee is all gone! ) Answer = input( do you want cream (y/n): ) print(counter) **will print: 10 9 8 7 6 5 4 3 2 1 blast off! . **this is an infinite loop print(counter) counter= counter +1.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents