[Tutor] Missing the Obvious Again??

Allan Crooks allan.crooks@btinternet.com
Tue, 03 Jul 2001 00:01:56 +0100


> In doing the exercises in "How To Think Like A Computer Scientist (Python)"
> I am trying the following:
> 
> def addTime(t1, t2):
>     sum = Time()
>     sum.hour = t1.hour + t2.hour
>     sum.minute = t1.minute + t2.minute
>     sum.second = t1.second + t2.second
>     return sum
> 
> currentTime = Time()
> currentTime.hour = 9
> currentTime.minute = 14
> currentTime.second = 30
> 
> breadTime = Time()
> breadTime.hour = 3
> breadTime.minute = 35
> breadTime.second = 0
> 
> doneTime = addTime(currentTime, breadTime)
> printTime(doneTime)
> 
> 
> Here is the output I get:
> 
> Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>>
> Traceback (most recent call last):
>   File "C:/Python21/Practice/addTime.py", line 24, in ?
>     printTime(doneTime)
> NameError: name 'printTime' is not defined
> 
> Must this be defined outside this file?  I expect to print the result but
> continue to get this message.  Thanks in advance for any help.

In this example, you haven't defined printTime anywhere else. The "printTime(doneTime)" line is the first time you've mentioned printTime, so maybe you've forgotten to define it in the code above.

You could replace it with:

print doneTime

if you wanted to....

Allan.