|
1 |
| - |
| 1 | +""" |
| 2 | +15. Time Calculator |
| 3 | +Write a program that asks the user to enter a number of seconds |
| 4 | +and works as follows: |
| 5 | +- There are 60 seconds in a minute. If the number of seconds entered by |
| 6 | +the user is greater than or equal to 60, the program should display |
| 7 | +the number of minutes in that many seconds. |
| 8 | +- There are 3600 seconds in an hour. If the number of seconds entered by |
| 9 | +the user is greater than or equal to 3600, the program should display |
| 10 | +the number of hours in that many seconds. |
| 11 | +- There are 86400 seconds in a day. If the number of seconds entered by |
| 12 | +the user is greater than or equal to 86400, the program should display |
| 13 | +the number of days in that many seconds. |
| 14 | +Starting out with Python. Third Edition. Tony Gaddis. |
| 15 | +Reference: |
| 16 | +(1) Starting out with Python, Third Edition, Tony Gaddis Chapter 3 |
| 17 | +(2) https://youtu.be/o_0PvX0s0zQ |
| 18 | +""" |
| 19 | +# Get the User Input(the number of seconds) and Convert to int |
| 20 | +number_of_seconds = int(input("Please Enter The number of seconds : ")) |
| 21 | +# Let save the flowing values in variable first |
| 22 | +one_minute = 60 |
| 23 | +an_hour = 3600 |
| 24 | +seconds_in_day = 86400 |
| 25 | +# Calculate All the Results |
| 26 | +number_of_minutes = number_of_seconds // one_minute |
| 27 | +number_of_hours = number_of_seconds // an_hour |
| 28 | +number_of_days = number_of_seconds // seconds_in_day |
| 29 | +# check All the conditions and display the Result |
| 30 | +if number_of_seconds >= 0 and number_of_seconds < one_minute: |
| 31 | + print(f"is only {number_of_seconds} seconds") |
| 32 | +elif number_of_seconds >= one_minute and number_of_seconds < an_hour: |
| 33 | + print("there is : " + str(number_of_minutes) + " minutes in " + \ |
| 34 | + str(number_of_seconds) + " seconds ") |
| 35 | +elif number_of_seconds >= an_hour and number_of_seconds < seconds_in_day: |
| 36 | + print("there is : " + str(number_of_hours) + " hours in " + \ |
| 37 | + str(number_of_seconds) + " seconds ") |
| 38 | +elif number_of_seconds >= seconds_in_day : |
| 39 | + print("there is : " + str(number_of_days) + " days in " + \ |
| 40 | + str(number_of_seconds) + " seconds ") |
0 commit comments