Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find bug
#1
def interleave(nums):
new_nums = []
index = 0
if len(nums) == 0:
return new_nums
for j in range(len(nums)):
for i in range(len(nums)):
new_nums.append(nums[j][index])
index += 1
return new_nums

# test cases!
if __name__ == '__main__':
# Part I
print("Testing Part I:")
print("Testing interleave() for nums = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]: " + str(
interleave([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))) # 3 lists with 3 elements each
print("Testing interleave() for nums = [[0, 1, 0], [1, 0, 0], [0, 0, 1]]: " + str(
interleave([[0, 1, 0], [1, 0, 0], [0, 0, 1]]))) # 3 lists with 3 elements each
print("Testing interleave() for nums = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]: " + str(
interleave([[1, 2], [3, 4], [5, 6], [7, 8], [9, 0]]))) # 5 lists with 2 elements each
print()

Function Call Return Value
interleave([[1,2,3],[4,5,6],[7,8,9]]) [1, 4, 7, 2, 5, 8, 3, 6, 9]
interleave([[0,1,0],[1,0,0],[0,0,1]]) [0, 1, 0, 1, 0, 0, 0, 0, 1]
interleave([[1,2],[3,4],[5,6],[7,8],[9,0]]) [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
Reply
#2
1) Please use code tags, so we can actually read the code.
2) Please share the entire traceback, so we can see what the error is.
3) Please share any input/output along with the expected output.

What did you reasonably expect us to do?  Look at that mess and try to figure out what you wanted?  lol
Reply
#3
Code(couldn't indent it somehow):

UNTAGGED CODE DELETED
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020