<< Chapter < Page | Chapter >> Page > |
This module is one in a collection of modules on Python designed for teaching ITSE 1359 Introduction to Scripting Languages: Python at Austin Community College in Austin, TX.
Earlier modules in this collection have included instruction on the following topics:
This has prepared you to use Python as a very fancy desk calculator.
The next step in learning to program with Python is to learn how to apply repetition, modularity, and decision logic to your scripts. This is oftenreferred to in computer jargon as control flow .
This module introduces control flow in general and explains the use of the while loop in Python as an example of control flow .
I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figuresand the Listings while you are reading about them.
(Note to blind and visually impaired students: Most of the Figures and all of the Listings inthis module are presented in plain text format and should be accessible using an audio screen reader or a braille display. Note however that the requiredindentation may not be properly represented by an audio screen reader.)
A typical script in the earlier modules looked something like the one shown in Listing 1 .
Listing 1 . Typical script from earlier modules. |
---|
# Illustrates extracting a
# list element and extracting# elements from a nested list
##-------------------------------
print("Create and print a list")listA = [100,200,300,400,500]
print(listA)print("Original length is:")
print(len(listA))print("Replace an element")
listA[2]= [2,4,8,16,32,64]
print("Print the modified list")print(listA)
print("Modified length is:")print(len(listA))
print("Extract and display each")print(" element in the list")
print(listA[0])
print(listA[1])
print(listA[2])
print(listA[3])
print(listA[4])
print("Extract and display each")print(" element in nested list")
print(listA[2][0])print(listA[2][1])
print(listA[2][2])print(listA[2][3])
print(listA[2][4])print(listA[2][5]) |
The output produced by the script in Listing 1 is shown in Figure 1 .
Notification Switch
Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?