{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

This preview shows pages 1–23. Sign up to view the full content.

Engineering Computation: Tutorial 08 Problem Solving with Computing, using the Python Language

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

View Full Document
Questions from Week 07? Programming Exercises from Zelle textbook 1 pg. 262 - 263 # 2, 3, 5, 6, 12. 2
What’s 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

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

View Full Document
Today’s 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

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

View Full Document
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

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

View Full Document
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 it’s impossible to know the number of iterations in advance. 6

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

View Full Document
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 it’s 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 it’s 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

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

View Full Document
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 c o n d i t i o n : block 7

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

View Full Document
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

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

View Full Document
While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 0 i < 4 output 8
While Loops Here is a trivial example: >>> i = 0 >>> while i < 4: i = i + 1 print i, i 0 i < 4 true output 8

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

View Full Document
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

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

View Full Document
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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 93

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

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

View Full Document
Ask a homework question - tutors are online