1

I'm creating a program in python that takes the hours, minutes, and seconds, and adds them all up as seconds. When I run the program I get back unexpected numbers, hundreds of characters long. I know it's very clunky, I'm still practicing python and making it more efficient, but here's my code

def to_secs(hours, minutes, seconds):
     fin_time = (hours * 3600) + (minutes * 60) + seconds
     return fin_time
total_hours = input("How many hours?")
total_minutes = input("How many minutes?")
total_seconds = input("How many seconds?")
total_time = to_secs(total_hours, total_minutes, total_seconds)
print(total_time)

1 Answers1

1

The method input() read data as string.

On your version, result of string * n(number) is string n times.

For example, "abc" * 3 == "abcabcabc" in Python.

you need to convert for integer.

total_hours = int(input("How many hours?"))
total_minutes = int(input("How many minutes?"))
total_seconds = int(input("How many seconds?"))
Joona Yoon
  • 314
  • 3
  • 16