[Tutor] pure function problem

Roelof Wobben rwobben at hotmail.com
Thu Sep 23 10:58:39 CEST 2010



Hello, 
 
I have to rewrite a function to a pure function.
So i have this :
 

class tijd :
    pass
def increment(time, seconds):
    sum = tijd()
    sum.seconds = time.seconds + seconds 
    
    if sum.seconds> 60 :
        minutes, seconds = divmod(sum.seconds, 60)
        sum.seconds = seconds 
        sum.minutes = time.minutes + minutes
    return sum
time = tijd()
time.hour = 20 
time.minutes = 20
time.seconds = 20 
seconds = 20
uitkomst = tijd()
uitkomst = increment(time, seconds)
print uitkomst.minutes, uitkomst.seconds
 
But now I get this error message :
 
Traceback (most recent call last):
  File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 22, in <module>
    print uitkomst.minutes, uitkomst.seconds
AttributeError: tijd instance has no attribute 'minutes'
 
So it looks like uitkomst has no attribute minutes but uitkomst is a instance of tijd which has a attribute minutes.
 
Roelof
  		 	   		  


More information about the Tutor mailing list