Professional Documents
Culture Documents
Ans 1 and 2
Ans 1 and 2
Ans 1 and 2
class Time:
def __init__(self,hr=0,mint=0,sec=0):
self.hour=hr
self.minute=mint
self.second=sec
def __str__(self):
return '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
def increment(time,seconds):
time.second+=seconds #245
m=time.second//60 #245//60=4=m
time.second=time.second-(m*60)#245-(4*60)=5=second
time.minute+=m
h=time.minute//60
time.minute=time.minute-(h*60)
time.hour+=h
return time
def add_time(self,other):
sum=Time()
sum.hour=self.hour+other.hour
sum.minute=self.minute+other.minute
sum.second=self.second+other.second
if sum.second>=60:
sum.second-=60
sum.minute+=1
if sum.minute>=60:
sum.minute-=60
sum.hour+=1
return sum
def __add__(self,other):
if isinstance(other,Time):
return self.add_time(other)
else:
return self.increment(other)
print('---------------')
start=Time(9,45)
duration=Time(1,35)
print(start+duration)
print('---------------')
start=Time(9,45)
print(start+1337)
'''import shutil, os
shutil.copy('F:\\file1.txt','F:\\a1\\5b.txt')''' #copying files
import shutil,os
os.chdir('C:\\')
shutil.copytree('F:\\swings', 'F:\\5c') #copying folders
#file writing
fo = open('F:\\nish.txt', 'a')
fo.write('Hello, disha1!\n')
fo.close()