ESTIMATED TIME TO COMPLETE: 10 minutes
Below are some short Python programs. For each program, answer the associated questions. Try to answer the questions without running the code. Check your answers, then run the code for the ones you get wrong. You'll learn the most this way, by figuring things out, instead of just running the code and reading off the answers. 1
myStr = '6.00x'
for char in myStr: print char print 'done' 2
greeting = 'Hello!'
count = 0 for letter in greeting: count += 1 if count % 2 == 0: print letter print letter print 'done' 3
school = 'Massachusetts Institute of Technology'
numVowels = 0 numCons = 0 for char in school: if char == 'a' or char == 'e' or char == 'i' \ or char == 'o' or char == 'u': numVowels += 1 elif char == 'o' or char == 'M': print char else: numCons -= 1 print 'numVowels is: ' + str(numVowels) print 'numCons is: ' + str(numCons) |
ArchivesCategories
All
|