开发者

Syntax error in python, need help for a project

I'm trying to find a way to fix this syntax error. I can't seem to find it to make the program run correctly. This is my code below

wrong = 0
test = raw_input("Please enter a 4 digit integer:")

def start(test):




    if test.isdigit():

        if wrong(test)==True:
            print 'Invalid input.  Four integers must be entered.'
        else:
            numbers = []

            for a in test:
                digits.append(a)
            a=calc(int(digits[0]))
            b=calc(int(digits[1]))
            c=calc(int(digits[2]))
            d=calc(int(digits[3]))


            code = str(c)+str(d)+str(a)+str(b)

            print 'The encrypted integer is:',code


    else:

        print 'You input wrong. Use numbers only.'


def calc(num):
    num+=7
    num%=10
    return num




def error(test):

    if len(test)<4 or len(test)>4:
        return True
    else:
        return False






start(test)

AND the fixed is ...

digits = 0 wrong = 0 test = raw_input("Please enter a 4 digit integer:")

def start(test):

if test.isdigit():

    if wrong(test)==True:
        print 'Invalid input.  Four integers must be entered.'
    else:
        numbers = []

        for a in test:
            digits.append(a)
        a=calc(int(digits[0]))
        b=calc(int(digits[1]))
        c=calc(int(digits[2]))
        d=calc(int(digits[3]))开发者_JAVA技巧


        code = str(c)+str(d)+str(a)+str(b)

        print 'The encrypted integer is:',code


else:

    print 'You input wrong. Use numbers only.'

def calc(num): num+=7 num%=10 return num

def wrong(test):

if len(test)<4 or len(test)>4:
    return True
else:
    return False

start(test)


You've called a function named wrong() but defined a function named error(). Is that the problem you're seeing?


Don't you mean if error(test)? 'wrong' is not a function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜