CSE 1010 Lecture Notes - Lecture 5: While Loop

45 views2 pages
jadetortoise401 and 55 others unlocked
CSE 1010 Full Course Notes
84
CSE 1010 Full Course Notes
Verified Note
84 documents

Document Summary

There may be a situation when you need to execute a block of code several number of times. A loop statement allows us to execute a statement or group of statements multiple times. Python programming language provides following types of loops to handle looping requirements. Repeats a statement or group of statements. While a given condition is true, it tests the condition before executing the loop body. The condition can be any expression that evaluates true or false. While count < 9: print( the count is: , count) Ex) n = 0 while n < 10: print(n) n = n + 1. Ex) import random num = random. randint(1, 10) while guess != num: guess = int(input( guess a number between 1 to 10 )) if guess < num: print( too low ) elif guess > num: print( too high ) print( correct! ) #if you don"t know how many times to iterate, probably best to use a while loop.

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