Convert Hours to Seconds

PythonBeginner
Practice Now

Introduction

In this challenge, you will create a simple time converter that transforms hours into seconds. This practical exercise helps reinforce your understanding of basic Python concepts including user input, mathematical operations, and type conversion.

Time Converter Implementation

Open the code editor and you'll find the template file seconds.py with helpful comments guiding you through the implementation.

Tasks

  • Create a program that converts hours to seconds
  • Handle user input for the number of hours
  • Calculate and display the equivalent number of seconds

Requirements

  • Work with the template file /home/labex/project/seconds.py
  • Replace the TODO comments with working code that:
    1. Uses input() to get hours with the prompt "Hours: "
    2. Converts the input string to an integer
    3. Calculates seconds (multiply hours by 3600)
    4. Prints the result using the format "Seconds: "

Working with Numbers

Here's a quick guide to help you with the conversion:

  • 1 hour = 60 minutes
  • 1 minute = 60 seconds
  • Therefore, 1 hour = 3600 seconds
  • Example calculation: 2 hours = 2 × 3600 = 7200 seconds

Example

When running your program:

$ python seconds.py
Hours: 3
Seconds: 10800

Another example:

$ python seconds.py
Hours: 1
Seconds: 3600

Summary

In this challenge, you have created a practical time converter program that demonstrates several fundamental Python concepts:

  • Taking user input with the input() function
  • Converting strings to integers using int()
  • Performing mathematical calculations
  • Formatting and displaying output with print()

These skills form the foundation for more complex programming tasks and real-world applications.

✨ Check Solution and Practice