Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
53 lines (43 loc) · 1.09 KB

File metadata and controls

53 lines (43 loc) · 1.09 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Time:
'''Represents Time in 24 hour format.
Attributes: hr,min,sec'''
def __init__(self,hour=0,minute=0,second=0):
self.hr=hour
self.min=minute
self.sec=second
def __str__(self):
return ('%.2d:%.2d:%.2d'%(self.hr,self.min,self.sec))
def __add__(self,other):
if isinstance(other,Time):
return self.add_time(other)
else:
return self.increament(other)
def add_time(self,other):
'''Adds to given time'''
second=self.to_sec() + other.to_sec()
return to_time(second)
def increament(self,seconds):
'''Adds seconds to time'''
seconds+=self.to_sec()
return to_time(seconds)
def to_sec(self):
min=self.hr*60 + self.min
sec=min*60 + self.sec
return sec
def to_time(sec):
t=Time()
t.hr,t.min=divmod(sec,3600)
t.min,t.sec=divmod(t.min,60)
return t
def main():
t1=Time(1,59,3)
print(t1)
t2=Time(2,3,4)
print(t2)
t3=Time()
t3=t1+t2
print(t3)
t4=Time()
t4=t1+360
print(t4)
main()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.