Programming Examples
Python program for addition of two times in hour and minute format
Write a python program which accept two times as input and displays the total time after adding both the entered times.
Sample Input :
Enter Time 1 :
Hour : 3
Minute : 40
Enter Time 2 :
Hour : 2
Minute : 35
Output:
Time 1 : 3Â Hour & 40Â Minute
Time 2 : 2Â Hour & 35Â Minute
Total Time : 6 Hour & 15 Minute
Solution
print("Enter Time 1 :")
h1=int(input("Hour : "))
m1=int(input("Minute : "))
print("Enter Time 2 :")
h2=int(input("Hour : "))
m2=int(input("Minute : "))
h3=h1+h2+(m1+m2)//60
m3=(m1+m2)%60
print("Time 1 :",h1," Hour &",m1," Minute")
print("Time 2 :",h2," Hour &",m2," Minute")
print("Total Time :",h3," Hour &",m3," Minute")
Output/ Explanation:
Enter Time 1 :
Hour : 3
Minute : 20
Enter Time 2 :
Hour : 1
Minute : 15
Time 1 : 3Â Hour & 20Â Minute
Time 2 : 1Â Hour & 15Â Minute
Total Time : 4 Hour & 35 Minute
>>>Â
========================Â
Enter Time 1 :
Hour : 2
Minute : 45
Enter Time 2 :
Hour : 2
Minute : 35
Time 1 : 2Â Hour & 45Â Minute
Time 2 : 2Â Hour & 35Â Minute
Total Time : 5 Hour & 20 Minute