【问题标题】:Syntax error in python, need help for a projectpython中的语法错误,需要项目帮助
【发布时间】:2011-04-26 04:38:55
【问题描述】:

我正在尝试找到解决此语法错误的方法。我似乎找不到它来使程序正确运行。 这是我下面的代码

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)

并且固定是...

数字 = 0 错误 = 0 test = raw_input("请输入4位整数:")

定义开始(测试):

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.'

定义计算(数字): 数字+=7 人数%=10 返回号码

定义错误(测试):

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

开始(测试)

【问题讨论】:

  • 不要让我们悬念:错误是什么?
  • 请记住显示您收到的错误消息。我们无法从这里看到您的屏幕,所以我们必须猜测。如果我们猜错了,您就是在浪费您和我们的时间。
  • 好的,这是一个简单的错误,当我调用它们时没有正确命名。

标签: python syntax


【解决方案1】:

您调用了一个名为 wrong() 的函数,但定义了一个名为 error() 的函数。这是你看到的问题吗?

【讨论】:

  • 我找到了,到处都说数字必须是数字
【解决方案2】:

你不是说if error(test)吗? 'wrong' 不是函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    相关资源
    最近更新 更多