Next / Previous / Contents / TCC Help System / NM Tech homepage

11.2. Scalar variables

Back around 1960, the hot language was FORTRAN. A lot of the work in this language was done using scalar variables, that is, a set of variable names, each of which held one number.

Suppose we've just had a snail race, and Judy finished in 87.3 minutes, while Kyle finished in 96.6 minutes. We can create Python variables with those values like this:

>>> judy = 87.3
>>> kyle = 96.6

To find the winner, we can use some if statements like this:

>>> if judy < kyle:
...     print "Judy wins with a time of", judy
... elif judy > kyle:
...     print "Kyle wins with a time of", kyle
... else:
...     print "Judy and Kyle are tied with a time of", judy
...
Judy wins with a time of 87.3
>>> 

If Judy and Kyle are the only two snails, this program will work fine. Malek puts this all into a script. After each race, he changes the first two lines that give the finish times, and then runs the script.

This will work, but there are a number of objections: