Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

def timing(minutes): # probably you should change these before returning, right?

ID: 3744327 • Letter: D

Question

def timing(minutes):

# probably you should change these before returning, right?...

num_fortnights = 0

num_days = 0

num_hours = 0

num_minutes = 0

if minutes >= 20160:

num_fortnights = minutes // 20160

minutes = minutes - (num_fortnights * 20160)

elif minutes >= 1440 and minutes < 20160:

num_days = minutes // 1440

minutes = minutes - (num_days * 1440)

elif minutes >= 60 and minutes < 1440:

num_hours = minutes // 60

minutes = minutes - (num_hours * 60)

num_minutes = minutes

# as always you can name your variables what you want, but

# if you use these names, this return statement is what we need.

return (num_fortnights, num_days, num_hours, num_minutes)

this is the code that I worked with and it works for almost all tests except 3 tests:

FAIL: test_timing_08 (__main__.AllTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Test_P1.py", line 141, in test_timing_08
def test_timing_08 (self): self.assertEqual(timing( 1561),(0, 1, 2, 1))
AssertionError: Tuples differ: (0, 1, 0, 121) != (0, 1, 2, 1)

First differing element 2:
0
2

- (0, 1, 0, 121)
? ^ --

+ (0, 1, 2, 1)
? ^


======================================================================
FAIL: test_timing_09 (__main__.AllTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Test_P1.py", line 142, in test_timing_09
def test_timing_09 (self): self.assertEqual(timing(20153),(0,13,23,53))
AssertionError: Tuples differ: (0, 13, 0, 1433) != (0, 13, 23, 53)

First differing element 2:
0
23

- (0, 13, 0, 1433)
? ^ ^^^

+ (0, 13, 23, 53)
? ^^ ^


======================================================================
FAIL: test_timing_10 (__main__.AllTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "Test_P1.py", line 143, in test_timing_10
def test_timing_10 (self): self.assertEqual(timing(76543),(3,11, 3,43))
AssertionError: Tuples differ: (3, 0, 0, 16063) != (3, 11, 3, 43)

First differing element 1:
0
11

- (3, 0, 0, 16063)
+ (3, 11, 3, 43)

----------------------------------------------------------------------
Ran 25 tests in 0.003s

do i need to make a loop for this to work?

Explanation / Answer

# assume the minutes parameter is an non-negative integer. # how many fortnights, days, hours, and minutes are included in that period? def timing(minutes): # probably you should change these before returning, right?... num_fortnights = minutes // (14 * 24 * 60) minutes %= (14 * 24 * 60) num_days = minutes // (24 * 60) minutes %= (24 * 60) num_hours = minutes // 60 minutes %= 60 return num_fortnights, num_days, num_hours, minutes