February 2006
Intermediate to advanced
648 pages
14h 53m
English
The program in Listing 1.1 shows the use of variables and expressions by performing a simple compound-interest calculation.
principal = 1000 # Initial amount
rate = 0.05 # Interest rate
numyears = 5 # Number of years
year = 1
while year <= numyears:
principal = principal*(1+rate)
print year, principal
year += 1
|
The output of this program is the following table:
1 1050.0 2 1102.5 3 1157.625 4 1215.50625 5 1276.2815625
Python is a dynamically typed language in which names can represent values of different types during the execution of a program. In fact, the names used in a program are really just labels for various quantities and objects. The assignment operator ...