Guidelines

Coding Quiz - Sorting Lists

In this coding quiz, you'll write a function that sorts a given list using Python's sort() function.

We'll create a simple program that takes a list of numbers from the user and sorts it in either ascending or descending order and then prints it out.

Parameter Format
def solution(numbers, is_ascending): return # Write your code here

The function receives the following 2 parameters:

  • numbers: The list of numbers to be sorted

  • is_ascending: A boolean indicating whether to sort in ascending order - True/False or 0/1


Constraints

  • The list received as the first argument must consist of integers.

  • The sorting order (ascending/descending) given as the second argument must be selectable by the user using True, False, 0, or 1.


Input/Output Examples

Example 1

  • Input: solution([3, 1, 4, 1, 5, 9, 2], True)

  • Output: [1, 1, 2, 3, 4, 5, 9]

Example 2

  • Input: solution([3, 1, 4, 1, 5, 9, 2], False)

  • Output: [9, 5, 4, 3, 2, 1, 1]

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help