def complexCodingTwo(listOfIntegers): """ This is a complex question. You can use objects learned before to implement it. Description is shown below. There is a list(listOfIntegers) originally...








































































































































































































































def complexCodingTwo(listOfIntegers):

"""

This is a complex question. You can use objects learned before to implement it.

Description is shown below.

There is a list(listOfIntegers) originally containing all the integers from 1 to n

(n can be any integer greater than 2). But due to some error, at least one of

the numbers went wrong in this list, which results in bad number(s) and loss of

right number(s).

Find the number(s) that are wrong and the number(s) that are missing.

Return them in a nested list(reportList). See examples and expalinations below.

Examples:

Input(listOfIntegers): [1, 1, 3, 3]

Output(reportList): [[1, 2], [3, 4]]

explaination: For [1, 1, 3, 3], original list should be [1, 2, 3, 4].

So second element should be 2 but it is 1 due to error.

Here the wrong number is 1, expected number is 2 and this should be recorded as [1, 2].

Then forth element should be 4 but it is 3 due to error.

Here the wrong number is 3, expected number is 4 and this should be recorded as [3, 4].

Thus the reportList to record all pairs will be [[1, 2], [3, 4]].

Input(listOfIntegers): [4, 2, 3, 4, 2, 3]

Output(reportList): [[4, 1], [2, 5], [3, 6]]

explaination: For [4, 2, 3, 4, 2, 3], original list should be [1, 2, 3, 4, 5, 6].

So first element should be 1 but it is 4 due to error.

Here the wrong number is 4, expected number is 1 and this should be recorded as [4, 1].

Then fifth element should be 5 but it is 2 due to error.

Here the wrong number is 2, expected number is 5 and this should be recorded as [2, 5].

Then last element should be 6 but it is 3 due to error.

Here the wrong number is 3, expected number is 6 and this should be recorded as [3, 6].

Thus the reportList to record all pairs will be [[4, 1], [2, 5], [3, 6]].

---------------------------------------------------------------------

listOfIntegers commented in the code is a sample(one of examples). The value could be changed

when robot runs your code, so make reportList = [[1, 2], [3, 4]] cannot ensure a right result

though this is right for the sample given. You need to solve this problem in a generic way.

And listOfIntegers at least holds two elements(and at least one bad number), but can be up to

hundred or thousand elements inside(and could be all wrong numbers).

You can uncomment listOfIntegers for your local print testing. And remember to comment it

again after your testing.

Hint:

1. think about [ xxx for xxx if xxx ] in list topic.

2. x == y is checking whether x and y have the same value;

x != y is checking whether x and y have differen values (True if they are different values).

This can be implemented in one line. But if you need more variables before reportList,

feel free to add your own variables. Just make sure don't name your variable

listOfIntegers or reportList to avoid the unexpected value replacement.

"""


# Please implement it below. See above for question description.

# listOfIntegers = [1, 1, 3, 3]

reportList =


return reportList
Nov 11, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here