Course Home
Syllabus
References
Reflections

Lessons

Related Links

Adding New Functions

Exercises

The exercises on this page are from How to Think Like a Computer Scientist: Learning with Python.

Open a new window in IDLE and add the following code:

def newLine():
print
def threeLines():
newLine()
newLine()
newLine()
print "First Line."
newLine()
print "Second Line."
print "Starting Line."
threeLines()
print "Finish Line."
  • Save the code to a file called
    newLine.py
  • With the newLine.py window selected, choose Run Module from the Run menu
  • What happens? Why?
  • Write a function called
    nineLines()
     that uses the
    threeLines()
     function three times to print nine new lines.
  • How would you print twenty-seven new lines?
  • Move the last three lines in the file to the top of the file and try Run Module again. What happens? Why? How do you fix the problem?