curriculum/challenges/english/blocks/daily-coding-challenges-python/69373793f5a867f769cde136.md
Given an array of numbers, determine if the numbers are sorted in ascending order, descending order, or neither.
If the given array is:
"Ascending"."Descending"."Not sorted".is_sorted([1, 2, 3, 4, 5]) should return "Ascending".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([1, 2, 3, 4, 5]), "Ascending")`)
}})
is_sorted([10, 8, 6, 4, 2]) should return "Descending".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([10, 8, 6, 4, 2]), "Descending")`)
}})
is_sorted([1, 3, 2, 4, 5]) should return "Not sorted".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([1, 3, 2, 4, 5]), "Not sorted")`)
}})
is_sorted([3.14, 2.71, 1.61, 0.57]) should return "Descending".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([3.14, 2.71, 1.61, 0.57]), "Descending")`)
}})
is_sorted([12.3, 23.4, 34.5, 45.6, 56.7, 67.8, 78.9]) should return "Ascending".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([12.3, 23.4, 34.5, 45.6, 56.7, 67.8, 78.9]), "Ascending")`)
}})
is_sorted([0.4, 0.5, 0.3]) should return "Not sorted".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(is_sorted([0.4, 0.5, 0.3]), "Not sorted")`)
}})
def is_sorted(arr):
return arr
def is_sorted(arr):
ascending = True
descending = True
for i in range(1, len(arr)):
if arr[i] < arr[i - 1]:
ascending = False
if arr[i] > arr[i - 1]:
descending = False
if ascending:
return "Ascending"
if descending:
return "Descending"
return "Not sorted"