Download presentation
Presentation is loading. Please wait.
Published byClaud Thornton Modified over 8 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.