0

I know this is probably quite a simple problem but I am having an issue with the formatting of my function. I am getting a lot of 'unexpected indent' and also 'unexpected token'. I keep trying to format the function correctly but I have no idea why these errors keep on appearing. Here is my function:

def stringCheck(stringForCheck, letterOrNumber):

    valid = True

    x = 0

    a = int(ord(stringForCheck)

    length = len(stringForCheck)

        if LetterOrNumber == 'Letter':

            lowerBoundary = 65

            upperBoundary = 90

        elif LetterOrNumber == 'Number':

            lowerBoundary = 48

            upperBoundary = 57

        while valid == True and x < length:

            if a < lowerBoundary or a > upperBoundary:

                valid = False

            else:

                valid = True

        x = x + 1

    stringCheck = valid



stringCheck('2','Number')
7
  • 1
    First of all what is your text editor? Use nano or vim when you are writing Python. python.org/dev/peps/pep-0008/#indentation Commented Oct 11, 2015 at 12:30
  • Hi, I am currently using Visual Studio 2015 Commented Oct 11, 2015 at 12:30
  • 1
    Hmm. Use Atom then: atom.io And could you share the debug output. Unexpected Token for which line? Commented Oct 11, 2015 at 12:32
  • 3
    There's missing a closing bracket here: a = int(ord(stringForCheck) Commented Oct 11, 2015 at 12:32
  • 1
    @Christoph Correct +1 Commented Oct 11, 2015 at 12:33

2 Answers 2

3
  1. Remove the unnecessary blank lines
  2. You are missing a closing bracket here: a = int(ord(stringForCheck)
  3. From the line if LetterOrNumber == 'Letter': to your while loop the lines have one indentation level too much.

After fixing the code it should look something like this:

def stringCheck(stringForCheck, letterOrNumber):
    valid = True
    x = 0
    a = int(ord(stringForCheck))
    length = len(stringForCheck)

    if LetterOrNumber == 'Letter':
        lowerBoundary = 65
        upperBoundary = 90
    elif LetterOrNumber == 'Number':
        lowerBoundary = 48
        upperBoundary = 57

    while valid is True and x < length:
        if a < lowerBoundary or a > upperBoundary:
            valid = False
        else:
            valid = True

    x = x + 1
    stringCheck = valid

stringCheck('2', 'Number')
Sign up to request clarification or add additional context in comments.

Comments

0

Try adding a close bracket after the line

    a = int(ord(stringForCheck))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.