In this project you will demonstrate your knowledge of decision making blocks such as if statements. Objectives Building on everything you have learned so far in this class, the objectives of this project are to demonstrate understanding of the following: • Input/output • Variables • Arithmetic expressions • Division and modulo • If-else statements • Equality and relational operators • Nested if-else statements • Code blocks and indentation Description Given the knowledge that there are 60 seconds in a minute, 60 minutes in an hour, and 24 hours in a day, you will prompt the user for the for the number of hours, minutes, and seconds as integer inputs, and your program will output the converted time so that the larger units are as large as possible. The possible output units are days, hours, minutes, and seconds. Make a note of the following: • Use singular and plural value names as appropriate, like 1 minute vs. 2 minutes. • Do not output a unit if its value is zero. For example: 2 hours and 1 second, NOT 0 days, 2 hours, 0 minutes and 1 second. • Your program must start by printing the welcome message: Welcome to the Time Conversion Calculator! • Your program should obtain the three inputs from the user, with the following prompts, in this order: Enter a number of hours: o Enter a number of minutes: • Enter a number of seconds: • You can assume that the user will never enter a negative number, but they can enter one or more O's. In the unique case that the user enters 0 for all three inputs, you should output: No time units to report. Refer to the sample runs below for how to format your output. Note that the time values are indented 4 spaces. Examples of a sample run: Welcome to the Time Conversion Calculator! Enter a number of hours: 1 Enter a number of minutes: 2 Enter a number of seconds: 3 Your time conversion is: 1 hour 2 minutes 3 seconds Goodbye! Welcome to the Time Conversion Calculator! Enter a number of hours: 0 Enter a number of minutes: 0 Enter a number of seconds: 0 Your time conversion is: No time units to report. Goodbye! Welcome to the Time Conversion Calculator! Enter a number of hours: 30 Enter a number of minutes: 20 Enter a number of seconds: 1000 Your time conversion is: 1 day 6 hours 36 minutes 40 seconds Goodbye!

Respuesta :

Answer:

print("Welcome to the Time Conversion Calculator")

#you need to check for each if user provided each of this inputs

while(True) :

   try:

       no_of_hours = int(input("Enter a number of hours:"))

       if type(no_of_hours) is int:

           break

       else:

           print('invalid input\n')

           no_of_hours = input('"Enter a number of hours:"\n')

   except ValueError:

       print('invalid amount\n')

       no_of_hours = input('"Enter a number of hours:"')

while(True) :

   try:

       no_of_minutes = int(input("Enter a number of minutes:"))

       if type(no_of_minutes) is int:

           break

       else:

           print('invalid input\n')

           no_of_minutes = input('"Enter a number of minutes:"\n')

   except ValueError:

       print('invalid amount\n')

       no_of_minutes = input('"Enter a number of minutes:"')

while(True) :

   try:

       no_of_seconds = int(input("Enter a number of seconds:"))

       if type(no_of_seconds) is int:

           break

       else:

           print('invalid input\n')

           no_of_seconds = input('"Enter a number of seconds:"\n')

   except ValueError:

       print('invalid input\n')

       no_of_seconds = input('"Enter a number of seconds:"')

# variables to keep track of days hours minutes

no_of_days = 0  

days = False

hours = False

minutes = False

seconds = False

hours_unit = "hours"

minutes_unit = "minutes"

seconds_unit = "seconds"

days_unit = "days"

#calculated values with initial values of zero

calc_minutes = 0

calc_hours = 0

if no_of_seconds >=  60:

   minutes= True

   calc_minutes = no_of_seconds // 60

   remaining_seconds =  no_of_seconds - (calc_minutes * 60)

   if remaining_seconds > 0:

         no_of_seconds = remaining_seconds

         seconds = True

         if no_of_seconds > 1:

            seconds_unit = "seconds"

         else:

            seconds_unit = "second"

no_of_minutes = no_of_minutes + calc_minutes

if no_of_minutes >=  60:

   hours = True

   calc_hours = no_of_minutes // 60

   remaining_minutes =  no_of_minutes - (calc_hours * 60)

   if remaining_minutes > 0:

         no_of_minutes = remaining_minutes

         minutes = True

         if no_of_minutes > 1:

            minutes_unit = "minutes"

         else:

             minutes_unit = "minute"

no_of_hours = no_of_hours + calc_hours

if no_of_hours >= 24:

   days = True

   no_of_days = no_of_hours // 24

   remaining_hours = no_of_hours -  (no_of_days * 24)

   if no_of_days > 1:

       days_unit = "days"

   else:

       days_unit = "day"

   if remaining_hours > 0:

       no_of_hours = remaining_hours

       minutes = True

       if no_of_hours > 1:

           hours_unit = "hours"

       else:

           hours_unit = "hour"

if no_of_days:

   print(str(no_of_days)+ " " + days_unit)

if no_of_hours:

   print(str(no_of_hours)+ " " + hours_unit)

if no_of_minutes:

   print(str(no_of_minutes)+ " " + minutes_unit)

if no_of_seconds:

   print(str(no_of_seconds)+ " " + seconds_unit)

print("Goodbye!")

Explanation:

This implementation is with the python programming language but can be rewritten in any language of your choose.

The program first forces users to provide the correct input using try catch.

it accepts the input, attempts to convert to int. if it fails, it repromts the user to enter the correct input

After uses boolean values to determine whether a value for seconds, minutes and hour is present inthe the question.

The calc values refers to the calculated values during runtime of minutes, hour and days

it then adds this calc values to the user inputs