Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

calling a method inside a class-Python

class Time:
 def __init__(self,x,y,z):
 self.hour=x
 self.minute=y
 self.second=z
 def __str__(self):
 return "({:02d}:{:02d}:{:02d})".format(self.hour, self.minute, self.second)
 def time_to_int(time):
 minutes=time.hour*60+time.minute
 seconds=minutes*60+time.second
 return seconds
 def int_to_time(seconds):
 time=Time()
 minutes,time.second=divmod(seconds,60)
 time.hour,time.minute=divmod(minutes,60)
 return time
 def add_time(t1,t2):
 seconds=time_to_int(t1)+time_to_int(t2)
 return int_to_time(seconds)
start=Time(9,45,00)
running=Time(1,35,00)
done=add_time(start,running)
print(done)

I am new to python and i've been doing some practice lately.I came across a question and i've written the code for the same.But I am repeatedly getting an error: "add_time is not defined". I tried defining a main() method but then it doesn't print anything.Please help.

Answer*

Draft saved
Draft discarded
Cancel
1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Feb 24, 2022 at 19:59

lang-py

AltStyle によって変換されたページ (->オリジナル) /