SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Decision Structures And Boolean Logic
Exercise:
Programming Exercises
Question:11 | ISBN:9780132576376 | Edition: 2

Question

Write a program that asks the user to enter a number of seconds, and works as follows:

• There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.

• There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.

• There are 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

COMPLETE PROGRAM CODE:

# Ask user to enter a number of seconds
seconds = int(input("Please enter a number of seconds: "))

# Calculate the number of minutes, hours, and days in the number of seconds
minutes = seconds / 60
hours = seconds / 3600
days = seconds / 86400

# Display the results
if seconds >= 86400:
    print(str(seconds) + " seconds is equal to " + str(days) + " days")
elif seconds >= 3600:
    print(str(seconds) + " seconds is equal to " + str(hours) + " hours")
elif seconds >= 60:
    print(str(seconds) + " seconds is equal to " + str(minutes) + " minutes")
else:
    print("No conversion necessary.")

OUTPUT 1:

Please enter a number of seconds: 240000
240000 seconds is equal to 2.7777777777777777 days

OUTPUT 2:

Please enter a number of seconds: 432000
432000 seconds is equal to 5.0 days

 

0 0

Discussions

Post the discussion to improve the above solution.