-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlab05.py
136 lines (102 loc) · 2.91 KB
/
lab05.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
class A:
def m(self):
print("m of A called")
class B(A):
def m(self):
print("m of B called")
class C(A):
def m(self):
print("m of C called")
class D(B,C):
pass
x = D()
x.m()
class Clock:
def __init__(self,hours=0, minutes=0, seconds=0):
self.__hours = hours
self.__minutes = minutes
self.__seconds = seconds
def set(self,hours, minutes, seconds=0):
self.__hours = hours
self.__minutes = minutes
self.__seconds = seconds
def tick(self):
""" Time will be advanced by one second """
if self.__seconds == 59:
self.__seconds = 0
if (self.__minutes == 59):
self.__minutes = 0
if self.__hours==23:
self.__hours = 0
else:
self.__hours += 1
else:
self.__minutes += 1;
else:
self.__seconds += 1;
def display(self):
print("%d:%d:%d" % (self.__hours, self.__minutes, self.__seconds))
def __str__(self):
return "%2d:%2d:%2d" % (self.__hours, self.__minutes, self.__seconds)
x = Clock()
print(x)
for i in range(100000):
x.tick()
print(x)
class Calendar:
months = (31,28,31,30,31,30,31,31,30,31,30,31)
def __init__(self, day=1, month=1, year=1900):
self.__day = day
self.__month = month
self.__year = year
def leapyear(self,y):
if y % 4:
# not a leap year
return 0;
else:
if y % 100:
return 1;
else:
if y % 400:
return 0
else:
return 1;
def set(self, day, month, year):
self.__day = day
self.__month = month
self.__year = year
def get(self):
return (self, self.__day, self.__month, self.__year)
def advance(self):
months = Calendar.months
max_days = months[self.__month-1]
if self.__month == 2:
max_days += self.leapyear(self.__year)
if self.__day == max_days:
self.__day = 1
if (self.__month == 12):
self.__month = 1
self.__year += 1
else:
self.__month += 1
else:
self.__day += 1
def __str__(self):
return str(self.__day)+"/"+ str(self.__month)+ "/"+ str(self.__year)
x = Calendar(1,1,2000)
for i in range(60):
x.advance()
print(x)
class CalendarClock(Clock, Calendar):
def __init__(self, day,month,year,hours=0, minutes=0,seconds=0):
Calendar.__init__(self, day, month, year)
Clock.__init__(self, hours, minutes, seconds)
def __str__(self):
return Calendar.__str__(self) + ", " + Clock.__str__(self)
x = CalendarClock(24,12,57)
print(x)
for i in range(10000):
x.tick()
for i in range(1000):
x.advance()
print(x)