Programming Examples
Python program that asks a user for a number of years and then prints out the number of days hours minutes and seconds
Write a program that asks a user for a number of years, and then prints out the number of days, hours, minutes, and seconds in that number of years.
How many years? 10
10.0 years is:
3650.0 days
87600.0 hours
5256000.0 minutes
315360000.0 seconds
Solution
y = float(input("How many years? "))
d = y * 365
h = d * 24
m = h * 60
s = m * 60
print(y, "years is:")
print(d, "days")
print(h, "hours")
print(m, "minutes")
print(s, "seconds")
Output/ Explanation:
How many years? 10
10.0 years is:
3650.0 days
87600.0 hours
5256000.0 minutes
315360000.0 seconds