Description

Lab Python 1

Visit http://docs.python.org/tutorial/index.html

Work through the tutorial, trying each of the steps and answering the following questions.

Using the Python Interpreter

Scan through this section, answering the following questions:

1) Where is Python installed on your machine?

2) Compare Python and Java in terms of passing arguments on the command line.

An Informal Introduction to Python

Try the calculator examples. You can skip over the complex / imaginary number section.

3) Compare Python, Perl, and Java Strings. Include mention of concatenation operators.

4) Type the following commands in the Python interpreter and record the response:

>>> a = "howdydoody"
>>> a
>>> a[5:]
>>> a[:5]

Briefly describe Python string indexing, comparing it to Java.

Skim through the Unicode section and move on to Lists.

5) Enter the Fibonacci program into Python. Use it to display Fibonacci numbers up to 1000. Take a screenshot and save it as fibo1.jpg.

More Control Flow Tools

6) Compare Java, Perl, and Python 'for' statements

7) Under "Defining Functions," what is a docstring? What Java concept is similar?

8) In the paragraph beginning "The execution of a function introduces...," What concept from our discussion of scoping is illustrated here?

9) In the paragraph beginning "The actual parameters (arguments) to a function call...," rewrite this main idea, using the concepts of r-value and l-value.

Skim the section on Default Argument Values

10) Under "Default Argument Values" and "Keyword Arguments," which of the language design criteria from chapter one are served by including these features in Python? Explain.

Skim the remainder of the page.

Data Structures

11) List the different Python data structures. Briefly describe each.

Modules

12) Follow the instructions for the Fibonacci numbers module. Use it to display Fibonacci numbers up to 1000. Take a screen shot and save it as fibo2.jpg.

PROGRAMMING TASK

Write an investment interest calculator, similar to the one you wrote in Perl. Create invest module in file invest.py with a function amortize that takes three arguments.

So if I want to show the interest earnings for a $10,000 loan at 6.5% annually over 12 months, I would enter:

>>> invest.amortize(10000,6.5,12)

and in response the program would print something like this:

  Month      InitBal    Interest     EndBal
  -----	    --------    --------   --------
  1         10000.00       54.17   10054.17
  2         10054.17       54.46   10108.63
  ...

 

Copyright © 1999-2008| Gene Rohrbaugh | Privacy Statement