COMP 1005 Lecture Notes - Lecture 6: Marsupial

14 views3 pages

Document Summary

Conditional execution if (condition): do statement(s) do the rest of the program. Alternative execution if (condition): do statement(s) else: do statement(s) do the rest of the program. Chained conditional if (condition): do statement(s) elif (condition): do statement(s) else: do statement(s) do the rest of the program. While loop while condition (true): do the true statement(s) do the rest of the program. Lecture 6 page 1 x = 1 while x < 6: print(x) x += 1. This code will count from 1 to 5, adding 1 each time until it reaches 5 then stopping. The code at the end x += 1 is used to add 1 to the variable x. If we put x += 3 then it would add 3 for each run of the loop. If we put x -= 1, it would subtract 1 for each run of the loop.

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