t_08[1] - Engineering Computation: Tutorial 08 Problem...

Info iconThis preview shows pages 1–32. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering Computation: Tutorial 08 Problem Solving with Computing, using the Python Language Questions from Week 07? Programming Exercises from Zelle textbook 1 pg. 262 - 263 # 2, 3, 5, 6, 12. 2 Whats in your toolbox? Print statement, string literals Basic calculator, integer division Variables Built-in functions Math library functions Non-branching programs Branching programs Python lists For loops Nested for loops Strings Converting between number system using Python Matplotlib Algorithms File Processing Graphics Functions Scope of Variables Comments Complex Conditions Testing and Debugging Exception Handling 3 Todays Topics: 1 While loops 2 Common Loop Patterns 3 Boolean Operators 4 Unit Testing 4 Loops Recall: the for loop for v a r i a b l e in l i s t : block 5 Loops Recall: the for loop for v a r i a b l e in l i s t : block The for loop executes a definite number of times. When the loop begins, Python knows how many times to go around (or iterate ) the body of the loop. This particular loop pattern is called a counted loop . 5 Loops The for loop is useful if you know how many iterations of the loop you need. 6 Loops The for loop is useful if you know how many iterations of the loop you need. Counted loops can also be written using a while loop. 6 Loops The for loop is useful if you know how many iterations of the loop you need. Counted loops can also be written using a while loop. There are situations where its impossible to know the number of iterations in advance. 6 Loops The for loop is useful if you know how many iterations of the loop you need. Counted loops can also be written using a while loop. There are situations where its impossible to know the number of iterations in advance. In such cases, a for loop can not be used. 6 Loops The for loop is useful if you know how many iterations of the loop you need. Counted loops can also be written using a while loop. There are situations where its impossible to know the number of iterations in advance. In such cases, a for loop can not be used. In such cases we can use a while loop ( conditional loop). 6 Loops while loops are sometimes called conditional loops because they iterate only as long as some condition is true. 7 Loops while loops are sometimes called conditional loops because they iterate only as long as some condition is true. the general form of the while loop is: while condition : block 7 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i i < 4 output 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i i < 4 output 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i i < 4 true output 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 1 i < 4 output 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 1 i < 4 output 1 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 1 i < 4 true output 1 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 2 i < 4 output 1 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 2 i < 4 output 1 2 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 2 i < 4 true output 1 2 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 3 i < 4 output 1 2 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 3 i < 4 output 1 2 3 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 3 i < 4 true output 1 2 3 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 4 i < 4 output 1 2 3 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 4 i < 4 output 1 2 3 4 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 4 i < 4 false output 1 2 3 4 8 While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i i < 4 output 1 2 3 4 8 For Loops in More Depth For loops can always be transformed into while loops....
View Full Document

This note was uploaded on 12/14/2010 for the course ENGINEERIN 1d04 taught by Professor Smith during the Spring '10 term at McMaster University.

Page1 / 93

t_08[1] - Engineering Computation: Tutorial 08 Problem...

This preview shows document pages 1 - 32. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online