2013-03-01 81 views
-5
for i in table.keys(): 
if table[i]==18798965: 
    first=i 
if table[i]==12738624: 
    second=i 
>>> print ("the encyrpted word is: %s%s") %(first,second); 

the encyrpted word is: %s%s 
Traceback (most recent call last): 
File "<pyshell#31>", line 1, in <module> 
print ("the encyrpted word is: %s%s") %(first,second); 
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple' 

我认为在大学的python版本与我在家里使用的版本不同。在控制台打印字符串时出错

任何人都可以帮我解决这个错误吗?

+3

-1 for URGENT请看 – 2013-03-01 17:48:22

+6

“紧急请关闭”你说的? Wokay。 – Xeo 2013-03-01 17:49:00

+0

这是一个新用户。不要这么苛刻。他们需要教练,而不是拒绝。 – 2013-03-01 17:53:15

回答

3

%您使用它的方式对字符串进行操作;您试图对由print()返回的值None进行操作。

移动格式化()内:

print ("the encyrpted word is: %s%s" %(first,second)) 

n.b .: Python没有在代码行的末尾使用;

+1

而大学Python的工作原理很可能是因为它在2.7左右,其中'print'只是一个关键字,所以'(“test”)'是只是父母表达,你可以使用'%'。 – Xeo 2013-03-01 17:50:21

+0

非常感谢您的回复,我正确地修改了代码。 道歉,如果我冒犯了我的'紧急'的任何人。该代码正在使用早期版本的Python。我回家准备提交我的作业,它不起作用。这是在3小时内到期:) 再次感谢。 – user2124568 2013-03-01 18:27:49