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, 23.06.2019 03:10
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
question
Computers and Technology, 23.06.2019 10:00
What is estimated time of arrival (eta)? a device that measures the acceleration (the rate of change of velocity) of an item and is used to track truck speeds or taxi cab speeds a gps technology adventure game that posts the longitude and latitude location for an item on the internet for users to find a north/south measurement of position the time of day of an expected arrival at a certain destination and is typically used for navigation applications
Answers: 3
question
Computers and Technology, 23.06.2019 17:00
*! 20 points! *jeff wants to create a website with interactive and dynamic content. which programming language will he use? a. dhtml b. html c. css d. javascript
Answers: 1
question
Computers and Technology, 23.06.2019 20:10
Leo is a recruitment executive for a large company. he has identified new labor resource requirements in both the marketing and production departments. what should be his first step in recruiting candidates for the positions? a. conduct background checks of candidates b. make job offers c. arrange interviews d. conduct reference checks e. place job ads on job sites
Answers: 1
You know the right answer?
For this assignment, you have to complete the function isSorted(numbers), which, informally, checks...
Questions
question
Biology, 14.09.2019 01:30
Questions on the website: 13722367