我对此很新,所以我不知道为什么这是错的。请帮忙。
谢谢你的帮助。
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 :(得分: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: ")))
这是一个正常运作的版本。确保花时间了解所使用的括号。
答案 1 :(得分:0)
如果您使用的是python2,则使用raw_input()而不是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: ")))
答案 2 :(得分:0)
将您的代码行拆分为更小的部分,查看哪一行会抛出错误,然后从那里开始。
错误告诉您它无法处理None
和str
对象之间的模运算。
确保在使用modulo之前一直处理字符串。