- Write a while loop that prints out all even numbers from 2 to 20.
- Write a program that reads in the following data from a file
and computes the average value:
- Given any specific definite (for) loop, write an indefinite (while) loop
that performs the same computation.
- Discussion question 3 on page 261
- Write a function called getLetter() that asks the user for a letter
and returns the given letter. Your function should check to make sure the user
enters just a single letter. If the user enters anything other than a single
letter, the function should ask again, until it receives valid input.
- Given the assignments for s and L, what is the value and type of
each expression? Try them in python to check your answers.
L = ["There are", "many", "like it,", "but this one", "is mine."]
s = "abcdefg"
"a" in L
"DEF" in s
- Trace through the following code, show the output from its entire
execution, and draw the stack before the return statement in
def main(): OUTPUT STACK
print "in main"
b = foo(5)
print "in foo"
biglist = 
for i in range (n):
sublist = ["h", i, i+10]
# draw stack here
What is the type and value of each of the following expressions:
- Write a program that reads in a list of words from a file infile.txt into a list of strings, and then calls a function (you write)
MakeAcronym that takes the list and returns a string that
is the acronym of all words in the list and prints it out. For example,
if the input file is:
Your program will print out the string "TGIF"