Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python Flow of Control CS 4320, SPRING 2015. Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.

Similar presentations


Presentation on theme: "Python Flow of Control CS 4320, SPRING 2015. Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the."— Presentation transcript:

1 Python Flow of Control CS 4320, SPRING 2015

2 Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the list s 1/7/2015CS 4320, SPRING 2015 2 for x in s: print(x)

3 Selection The semantics of the if statement are familiar, however the syntax is different from Java The body of each part of the ‘if’ must be indented. Four spaces is pretty standard. ◦The indentation must be consistent throughout the body 1/7/2015CS 4320, SPRING 2015 3 If x < 3: print(‘small’) elif x < 5: print(‘medium’) else: print(‘large’)

4 Example Get a running total of the positive elements in a list of numbers 1/7/2015CS 4320, SPRING 2015 4

5 Ranges For stepping through ranges of integers, the range function is available range(10) is the numbers from 0 to 9, inclusive range(5,10) is the numbers from 5 to 9, inclusive range(5,10,2) is the numbers 5, 7 and 9 1/7/2015CS 4320, SPRING 2015 5


Download ppt "Python Flow of Control CS 4320, SPRING 2015. Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the."

Similar presentations


Ads by Google