This would work assuming the input is only lowercase or only uppercase.
alphacheck('abc')
would return True, while
alphacheck('aBc')
would return False (because B < a < c)
You can solve this by converting the input string to lower or upper, like this:
x = x.lower()
It's good that you're trying to make the code readable, but IMO you're using too much comments and not expressive enough naming. It's often too easy to write comments that are just plain wrong, e.g. like here
# Using a recursive formula and checking for the base case when the string is of less than one character
if len(x) <= 1:
you're checking if x's length is less than or equal to 1, but in the comment you're saying that the check is for length < 1. It's a pretty unimportant mistake here, but it's just one of the many ways that excessive commenting can be bad. I would like less comments, and more expressive names -- something like this:
def is_alphabetical_ordered(input_string):
'''This function checks if a given string is in Alphabetical order'''
input_string = input_string.lower()
last_index = len(input_string) - 1
if len(input_string) <= 1:
return True
elif input_string[last_index - 1] <= input_string[last_index]:
input_string = input_string[:last_index]
return is_alphabetical_ordered(input_string)
else:
return False
More on readability
For a really concise and insightful explanation of the purpose of comments, read rolfl's answer to this codereview questionthis codereview question.
I also highly recommend reading Robert Martin's Clean Code, as it goes more deeply into readability (among other things) — beyond comments and naming.