subject

For this assignment, you have to complete the function isSorted(numbers), which, informally, checks if an input list of number is sorted in ascending order. Formally, the function input is a list of numbers numbers and returns a tuple x, y where x is a boolean (True / False) that indicates if the list is sorted and y is an integer index denoting the index of the first out of order number or -1 if the list is sorted. In other words, y is an integer that denotes the index in the list where the corresponding number is less than the previous number in the list.

Example 1: if the list is numbers = [0, 1, 2, 3, 4, 5]. The output will be.

The list is sorted.
Example 2: if the list is numbers = [0, 1, 1, 2, 3, 4, 5]. The output will be.

The list is sorted.
Note that, in this example, the number 1 appeared twice sequentially. We will consider this as sorted also, since the later number is not less than the earlier number.

Example 3: if the list is numbers = [0, -10, 2, 3, 4, 5]. The output will be.

The list is not sorted. The out of order index is 1
We have put comments in the template code, to show how Unpacking works. Please read and try to understand them. Ask your TA if you find it confusing. I am sure they will help!

Hint: Your function will look something like this.

def isSorted(numbers):
'''
your code
one return statement here
return (False, i)
'''
return (True, -1)
here is what I already did

def isSorted(numbers):
for i in range(1,len(numbers)):
if numbers[i] return (False, i)
return (True,-1)

def main():
numbers = [0,-10,2,3,4,5]
returnedIsSorted, returnedIndex = isSorted(numbers)
if returnedIsSorted:
print('The list is sorted')
else:
print('The list is not sorted. The out of order index is {}'.format(returnedIndex))

if __name__=='__main__':
main()

there is grade:

1: UnitTest1keyboard_arrow_up

0 / 2

Testcase 1: Example 1

Test feedback

isSorted(numbers) incorrectly returned None

2: UnitTest2keyboard_arrow_up

0 / 2

Testcase 2: Example 2

Test feedback

isSorted(numbers) incorrectly returned None

3: UnitTest3keyboard_arrow_up

2 / 2

Testcase 3: Example 3

4: UnitTest4keyboard_arrow_up

0 / 2

Unseen Testcase 1

Test feedback

isSorted(numbers) incorrectly returned None

5: UnitTest5keyboard_arrow_up

2 / 2

Unseen Testcase 2

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:10
How can i delete permalinks from a word press site?
Answers: 1
question
Computers and Technology, 23.06.2019 05:30
Sally is editing her science report about living things. she needs to copy a paragraph from her original report. order the steps sally needs to do to copy the text to her new document.
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Which of the following tasks is an audio technician most likely to perform while working on a nature documentary? (select all that apply). eliminating potentially distracting background noise adding sound effects making sure the lighting is adequate for a particular scene changing the narration to better match the mood of the documentary
Answers: 3
question
Computers and Technology, 23.06.2019 19:40
Use a physical stopwatch to record the length of time it takes to run the program. calculate the difference obtained by calls to the method system.currenttimemillis() just before the start of the algorithm and just after the end of the algorithm. calculate the difference obtained by calls to the method system.currenttimemillis() at the start of the program and at the end of the program so that the elapsed time includes the display of the result. use the value returned by the method system.currenttimemillis() just after the end of the algorithm as the elapsed time.
Answers: 3
You know the right answer?
For this assignment, you have to complete the function isSorted(numbers), which, informally, checks...
Questions
question
Biology, 27.10.2019 03:43
Questions on the website: 13722363