2015-09-02 107 views
-4

我对此很新,所以我不知道为什么这是错误的。请帮忙。我不知道为什么我的Python代码不能正常工作

谢谢,如果你帮忙。

print("%s is a very %s person. They usually spend all their time %s.") % input("Please enter a name: "), input("Please enter an adjective: "), input("Please eneter an ing verb: ") 

这是错误我得到:

Traceback (most recent call last): 
    File "C:\Python34\firstthingy.py", line 1, in <module> 
    print("%s is a very %s person. They usually spend all their time %s.") % input("Please enter a name: "), input("Please enter an adjective: "), input("Please eneter an ing verb: ") 
TypeError: unsupported operand type(s) for %: 'NoneType' and 'str' 

回答

0

如果您使用python2然后使用的raw_input(),而不是输入()

print("{0} is a very {1} person. They usually spend all their time {2}.".format(input("Please enter a name: "), input("Please enter an adjective: "), input("Please eneter an ing verb: "))) 
0

分裂您的代码行成小块,看哪一个抛出错误,并从那里去。

错误是告诉你它不能处理Nonestr对象之间的模操作。

确保您在使用模数前一直处理字符串。

2

你错位了括号。如果字符串中有多个%格式化项目,则必须将参数包装在括号(一个元组)中。

print("%s is a very %s person. They usually spend all their time %s." % (input("Please enter a name: "), input("Please enter an adjective: "), input("Please eneter an ing verb: "))) 

这是一个正在运行的版本。确保你花时间了解使用的括号。

相关问题