Computers and Technology, 05.03.2020 21:36, Victor3756
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
Answers: 2
Computers and Technology, 23.06.2019 08:00, seaotter7140
Michael has written an e-mail to his employees that describes a new product special that will be introduced to the customers next week. by taking time to make sure the e-mail is well written, logical, and organized, michael has made sure his message has the characteristics of a) effective communicationb) ineffective communicationc) barriers to communicationd) workplace communication
Answers: 2
Computers and Technology, 24.06.2019 08:00, nataliamontirl4230
Java the manager of a football stadium wants you to write a program that calculates the total ticket sales after each game
Answers: 1
Computers and Technology, 24.06.2019 17:40, penacesar18p9jrdh
The value of sin(x) (in radians) can be approximated by the alternating infinite series create a function (prob3_2) that takes inputs of a scalar angle measure (in radians) and the number of approximation terms, n, and estimates sin(x). do not use the sin function in your solution. you may use the factorial function. though this can be done without a loop (more efficiently), your program must use (at least) one. you may find the mod() function useful in solving the problem.
Answers: 1
Computers and Technology, 24.06.2019 22:00, yilianblanco
Aobject is used for displaying the results of a question based on stored data. a. query b. report c. table d. form
Answers: 2
For this assignment, you have to complete the function isSorted(numbers), which, informally, checks...
Chemistry, 09.07.2019 16:30
Physics, 09.07.2019 16:30
Mathematics, 09.07.2019 16:30
Biology, 09.07.2019 16:30
Biology, 09.07.2019 16:30