开发者

Python indent error. I can't figure out what's wrong here

I'm using notepad++ which shows the different indents, etc. I keep getting an error code on line 26:

return firstNum, secondNum, thirdNum

Here's the full code. If anyone can see what's going on here, that would be great. I've already killed开发者_开发百科 myself too much over this. I'm sorry if my first question didn't have a specific "question"

option = 1
while option !=0:
    print "\n\n\n************MENU************"
    print "1. Counting"
    print "2. Fibbonacci Sequence"
    print "0. GET ME OUTTA HERE!"
    print "*" * 28

    option = input("Please make a selection: ") #counting submenu
    if option == 1:
        print "\n\n*******Counting Submenu*******"
        print "1. Count up by one"
        print "2. Count down by one"
        print "3. Count up by different number"
        print "4. Count down by different number"
        print "*" * 28

        countingSubmenu = input("Please make a selection: ")
        def getNum():
            firstNum = input("Please state what number to start at: ")
            secondNum = input("Please state swhat number to end at: ")
            if countingSubmenu == 3 or countingSubmenu == 4:
                thirdNum = input("Please state what increment you would want to go up by: ")
                return firstNum, secondNum, thirdNum
            else:
                return firstNum, secondNum

        if option == 1:
            getNum(firstNum, secondNum, thirdNum)
            for x in range(firstNum, secondNum+1, 1):
                print x
            print "End of test." #def getNum():


The following three lines use tabs instead of spaces:

                return firstNum, secondNum, thirdNum
            else:
                return firstNum, secondNum

You can see this fairly easily by attempting to edit the question, you will see tabs show up as 8 spaces and the indentation will be visibly off.

Erase all the whitespace before these lines and indent them again with only spaces and you shouldn't get an indentation error.

Your code still may not be correct, since the function getNum does not accept any arguments yet you call it with three.

edit: I think that what you are trying to do is get the return values when you call the getNum function, to do that you should be calling it like this:

firstNum, secondNum, thirdNum = getNum()

or...

result = getNum()
firstNum, secondNum, thirdNum = result

It will probably be easier if you always have getNum return the same number of values. So replace the line return firstNum, secondNum with return firstNum, secondNum, None.


You have three \t before that line and you're using four spaces everywhere else (it is also in front of else and the other return which follow). There is a setting in Notepad++ to let you always use spaces for tabs. Because I use it for Python (even though it is only occasionally), this is always turned on for my machines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜