DNPotapov / Codewars-katas-

0 stars 0 forks source link

Alphabetically ordered (7 kyu) #1

Open DNPotapov opened 1 year ago

DNPotapov commented 1 year ago
def alphabetic(s):
    if len(s) == 0:
        return True
    save = ord(s[0])
    for item in s:
        print(ord(item))
        if save > ord(item):
            return False
        save = ord(item)
    return True
DNPotapov commented 1 year ago

Your task is very simple. Just write a function takes an input string of lowercase letters and returns true/false depending on whether the string is in alphabetical order or not.

Examples (input -> output) "kata" -> false ('a' comes after 'k') "ant" -> true (all characters are in alphabetical order) Good luck :)

DNPotapov commented 1 year ago

https://www.codewars.com/kata/5a8059b1fd577709860000f6