I&C SCI 31 Lecture Notes - Lecture 7: Leap Year, Boolean Expression

35 views1 pages

Document Summary

##more about selection def is_leap_year (year:int) -> bool: #python uses bool as boolean type. ## elif replaces else if and allows all checks to be aligned. ## rewrite the function above with elif def is_leap_year (year:int) -> bool: #python uses bool as boolean type. #if we want to check multiple years, we can call this function in a loop. #we can ask the user for year and print whether it is a leap year. #when the user is done, zero can be entered for a year. ## on seeing a sentinel value we get out of the loop. ## such a loop is called the while loop. Test the boolean expression if it"s true, do the body if it"s false, get out of the loop. While loops can repeat forever if the boolean expression never becomes false. That"s an infinite loop and is usually a bug. We use while loops for repeating an unpredictable (potentially.

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