How to solve the total amount of seconds using python

110 Views Asked by At

I am learning python as a novice and I was asked to solve the total of seconds in the problem. I was given the format but it still seems that I can not get a hand of it. it keeps telling me that I didn't get the minute and seconds part

I tried this:

def get_seconds(hours, minutes, seconds):
  return 3600*hours + 60*minutes + seconds

amount_a = get_seconds(3600*2 + 60*30 + 0*0)
amount_b = get_seconds(0 + 60*45 + 15)
result = amount_a + amount_b 
print(result)

expecting to get it right as i think i imputed everything correctly but instead i was getting this:

Error on line 4:
    amount_a = get_seconds(3600*2 + 60*30 + 0*0)
TypeError: get_seconds() missing 2 required positional arguments: 'minutes' and 'seconds'
2

There are 2 best solutions below

1
On

Your function already does the job of multiplying hours by 3600 and minutes by 60. The point is for you to pass the hours, minutes, and seconds as separate arguments, like this:

amount_a = get_seconds(2, 30, 0)   # 2 hours and 30 minutes
amount_b = get_seconds(0, 45, 15)  # 45 minutes and 15 seconds
result = amount_a + amount_b       # total seconds
print(result)  # 11715
0
On

Your function is OK.

As the function computes the total from the 3 arguments. When you call it, just pass the arguments.

def get_seconds(hours, minutes, seconds):
  return 3600*hours + 60*minutes + seconds

amount_a = get_seconds(2, 30, 0)
amount_b = get_seconds(0, 45, 5)
result = amount_a + amount_b 
print(result)