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

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad