Menu Close

Units of time in Python….FTC

Create a program that reads a duration from the user as a number of days, hours, minutes, and seconds. Compute and display the total number of seconds represented by this duration.

a=int(input("Days: "))
b=int(input("Hours: "))
c=int(input("Minutes: "))
d=int(input("Seconds: "))
e=d+c*60+b*3600+a*24*3600

print("\nDays= " + str(a))
print("Hours= " + str(b))
print("Minutes= " + str(c))
print("Seconds= " + str(d))
print("Total= " + str(e))


INPUT_1:
Days:  1
Hours:  0
Minutes:  0
Seconds:  0

OUTPUT:
Days=  1
Hours=  0
Minutes=  0
Seconds=  0
Total=  86400


INPUT_2:
Days:  2
Hours:  12
Minutes:  35
Seconds:  25

OUTPUT:
Days=  2
Hours=  12
Minutes=  35
Seconds=  25


ILLUSTRATION

Executed using python3