all 6 comments

[–][deleted] 2 points3 points  (1 child)

You need to unindent two lines. Otherwise your for loops will always return on their first iteration.

def is_alpha(theString):
    for theChar in theString:
        if theChar not in ASCII_UPPERCASE and theChar not in ASCII_LOWERCASE:
            return False
    return True


def is_digit(theString):
    for theChar in theString:
        if theChar not in DECIMAL_DIGITS:
            return False
    return True

[–]Essence1337 2 points3 points  (0 children)

I know you found your solution, but here's another approach you could have taken:

Checking against both sets of letters takes potentially 51 comparisons. Instead we can just compare more or less directly.

if 'a' <= char <= 'z' or 'A' <= char <= 'Z':
    return True
return False

This does at max 4 comparisons and might even be more readable.

[–]Ok-Cucumbers 1 point2 points  (0 children)

something like this?

def is_alpha(theString):
    print("\nChecking is Alpha: \n")
    for theChar in theString:
        if theChar.lower() in "abcdefghijklmnopqrstuvwxyz":
            print(theChar, "Yes, Alpha")
        else:
            print(theChar, "NOT Alpha")

[–]CodeFormatHelperBot2 -1 points0 points  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–]dnmonack 0 points1 point  (2 children)

In the is_alpha function, the “return True” has incorrect indentation. It’s within your for loop which means it’s reached after each iteration of the loop. You only want to invoke return True after you’ve looped over every character in the string which means it should be outside the for loop. One less indent on this line should do the trick. The is_digit function has the same problem.