34.1k views
2 votes
Write a program which prompts the user to enter a number of seconds and then reports the number of years, days, hours, and minutes the number represents.

Please enter a number of seconds: 65000000000 [Enter] 65000000000 seconds is approximately 2061 years, 49 days, 19 hours, 33 minutes and 20 seconds.


Demonstrate the program using: 65000000000, 123456789, and 987654321 (One screen shot for each)

1 Answer

2 votes

Answer:

time = float(input(" Input Time in Seconds: "))

years = time // (365*24*60*60)

time = time % (365*24*60*60)

day = time // (24*3600)

time = time % (24*3600)

hour = time // 3600

time = time % 3600

minutes = time // 60

time = time % 60

seconds = time

print(years,"years")

print(day, "days")

print(hour, "hours")

print(minutes, "minutes")

print(seconds, "seconds")

Step-by-step explanation:

The code is written in python programming language.

Line 1: time = float(input(" Input Time in Seconds: "))

prompts the user to input a time in seconds.

The value inputted is taken through the remaining steps.

Line 2: years = time // (365*24*60*60)

converts seconds into years and floor division is used to ensure that the result is an integer with noting after the decimal (no remainder).

Line 3: time = time % (365*24*60*60)

modulo division is used to get the remainder (seconds that were not converted to years) and then passes the output as the "New" time.

Line 4: day = time // (24*3600)

converts the "New" time to days and floor division is used to ensure there's noting after the decimal.

line 5: time = time % (24*3600)

modulo division is used to get the remainder (seconds that were not converted to days) and then passes the output as the "New" time.

line 6: hour = time // 3600

converts the "New" time to hours and floor division is used to ensure there's noting after the decimal.

line 7: time = time % 3600

modulo division is used to get the remainder (seconds that were not converted to hours) and then passes the output as the "New" time.

line 8: minutes = time // 60

converts the "New" time to minutes and floor division is used to ensure there's noting after the decimal.

line 9: time = time % 60

modulo division is used to get the remainder (seconds that were not converted to hours) and then passes the output as the "New" time.

line 10: seconds = time

It passes the remaining seconds to seconds

The last section of the code outputs the answer in years, days, hours minutes and seconds

print(years,"years")

print(day, "days")

print(hour, "hours")

print(minutes, "minutes")

print(seconds, "seconds")

Write a program which prompts the user to enter a number of seconds and then reports-example-1
User FrancoTampieri
by
5.1k points