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 def in order(nums):<br># Type your code here.<br>2<br>4 if<br>main<br>':<br>name<br>==<br># Test out-of-order example<br>nums1 = [5, 6, 7, 8, 3]<br>if in order(nums1):<br>print('In order')<br>else:<br>6<br>8<br>9<br>10<br>print('Not in order')<br>11<br># Test in-order example<br>numms2 = [5, 6, 7, 8, 10]<br>if in order(nums2):<br>print('In order')<br>else:<br>12<br>13<br>14<br>15<br>16<br>17<br>print('Not in order')<br>

Extracted text: main.py Load default template... 1 def in order(nums): # Type your code here. 2 4 if main ': name == # Test out-of-order example nums1 = [5, 6, 7, 8, 3] if in order(nums1): print('In order') else: 6 8 9 10 print('Not in order') 11 # Test in-order example numms2 = [5, 6, 7, 8, 10] if in order(nums2): print('In order') else: 12 13 14 15 16 17 print('Not in order')

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here