8.28 LAB: Check if list is sorted Write the in_order() function, which has a list of integers as a parameter, and returns True if the integers are sorted (in order from low to high) or False...



8.28 LAB: Check if list is sorted






Write the in_order() function, which has a list of integers as a parameter, and returns True if the integers are sorted (in order from low to high) or False otherwise. The program outputs "In order" if the list is sorted, or "Not in order" if the list is not sorted.


Ex: If the list passed to the in_order() function is [5, 6, 7, 8, 3], then the function returns False and the program outputs:


Not in order

Ex: If the list passed to the in_order() function is [5, 6, 7, 8, 10], then the function returns True and the program outputs:


In order

Note: Use a for loop.DO NOT use sorted() or sort().




main.py<br>Load default template...<br>1<br>2 def in order(nums):<br>y = [nums1[x-1] <= nums1[x] for x in range(1, len(nums1))]<br>return all(z ==<br>3<br>4<br>y[0] for z in y)<br>5<br>6 if<br># Test out-of-order example<br>nums1 = [5, 6, 7, 8, 3]<br>if in order(nums1):<br>print('In order')<br>name<br>main<br>7.<br>8<br>10<br>11<br>else:<br>12<br>print('Not in order')<br>13<br>14<br>

Extracted text: main.py Load default template... 1 2 def in order(nums): y = [nums1[x-1] <= nums1[x]="" for="" x="" in="" range(1,="" len(nums1))]="" return="" all(z="=" 3="" 4="" y[0]="" for="" z="" in="" y)="" 5="" 6="" if="" #="" test="" out-of-order="" example="" nums1="[5," 6,="" 7,="" 8,="" 3]="" if="" in="" order(nums1):="" print('in="" order')="" name="" main="" 7.="" 8="" 10="" 11="" else:="" 12="" print('not="" in="" order')="" 13="">

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here