CSCA08H3 Lecture Notes - Lecture 8: Boolean Expression, If And Only If

60 views2 pages

Document Summary

Note: code from the lecture can be found on the course website when it is posted. All code up to now has been linear. Now we"re going to learn how to write adaptive code. Allows us to execute code only if some condition is met and skip lines otherwise. Block is a series of python statements. Iff condition evaluates to true, then block is executed. Example: if (grade >= 50): print ( you passed! ) If you didn"t pass, no code will be run. Else covers all other cases of the if statement. If-else general form: if condition: else: block1 block2. Iff block1 doesn"t run, block2 will run. More example code will be posted on the course website. We can have more than 2 options. Makes it easier to check several conditions in a row; you can combine any number of elif statements in a row.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents