CS 149
Professor: Alvin Chao
For loops
Counting Loops
frame = 1
scores = [9, 7, 8, 5, 4, 9, 8, 6, 2, 1]
total = 0
for i in range(0,len(scores)):
// Get bowling scores for this frame.
// Do some fancy calculations.
// Show a turkey animation if needed...
total += scores[i]
For Loops pre-test
frame = 1
scores = [9, 7, 8, 5, 4, 9, 8, 6, 2, 1]
total = 0
for i in range(0,len(scores)):
// Get bowling scores for this frame.
// Do some fancy calculations.
// Show a turkey animation if needed...
total += scores[i]
Loops and Scope
for i in range(0,9):
print(i)
for i in “0123456789”:
print(i)
Problem #1
for i in range(0, 3):
print(i)
Problem #1
for i in range(0, 3):
print(i)
0
1
2
Naming Index Variables
def count_x(word):
count = 0
for i in range(len(word)):
if (word[i] == 'X'):
count += 1
return count
Naming Index Variables
Coding Bat
List-1 problems: first_last6, common_end, sum3, reverse3
Setup an account with your dukes.jmu.edu email and link the Teacher Share in preferences to my chaoaj@jmu.edu account
Parts of this activity are based on materials developed by Chris Mayfield and Nathan Sprague.
</end>