-1

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'
0x5453
  • 12,753
  • 1
  • 32
  • 61
  • `get_second()` requires 3 arguments. However, you are only passing one argument which is the result of a calculation (probably the same calculation that `get_seconds()` is supposed to do). – Code-Apprentice Nov 10 '22 at 15:40
  • I'm guessing those should be `get_seconds(2, 30, 0)` and `get_seconds(0, 45, 15)`, respectively. The whole point of the `get_seconds` function is to do the math for you, so you shouldn't be doing that same math outside of the function. – 0x5453 Nov 10 '22 at 15:40
  • don't post such questions here! first learn python properly you don't even know how to pass arguments to the function and your logic is incorrect too. – Ayush Nov 11 '22 at 18:38

2 Answers2

1

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
Samwise
  • 68,105
  • 3
  • 30
  • 44
0

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)
0x0fba
  • 1,520
  • 1
  • 1
  • 11