【发布时间】: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
开始(测试)
【问题讨论】:
-
不要让我们悬念:错误是什么?
-
请记住显示您收到的错误消息。我们无法从这里看到您的屏幕,所以我们必须猜测。如果我们猜错了,您就是在浪费您和我们的时间。
-
好的,这是一个简单的错误,当我调用它们时没有正确命名。