Name = input("What is your Name?")
Hobby = input("What is your Hobby
Color = input("What is your favorite Color?")
print ("Ah, so your Name is %s, your Hobby is %s, ") \
("and your favorite Color is %s. " % (Name, Hobby, Color)
嗨,大家好!
我几天前就已开始编码了,并打算查询代码。
现在......我的问题是这段代码不起作用。我已经测试了一些为什么它没有但我无法找到错误的东西。
运行时会显示错误消息:
Traceback (most recent call last):
File "/Users/master/Documents/Untitled3.py", line 6, in <module>
("and your favorite Color is %s.") (Name,Hobby,Color)
TypeError: 'NoneType' object is not callable
答案 0 :(得分:0)
您正在尝试调用print语句的结果:
result_of_print = print("Ah, so your Name is %s, your Hobby is %s, ")
result_of_print("and your favorite Color is %s. " % (Name, Hobby, Color))
但result_of_print
为None
。
更正括号:
print("Ah, so your Name is %s, your Hobby is %s, "
"and your favorite Color is %s. " % (Name, Hobby, Color))
答案 1 :(得分:0)
问题在于你正在关闭pirnt功能
打印(“啊,所以你的名字是%s,你的爱好是%s”,)(就在这里)\(“和你最喜欢的颜色是%s。”%(姓名,爱好,颜色)
您可以执行print ("Ah, so your Name is %s, your Hobby is %s, "+
"and your favorite Color is %s. " % (Name, Hobby, Color))
答案 2 :(得分:-1)
以下是完整的工作代码: 您使用的格式不适合打印。
Name = input("What is your Name?")
Hobby = input("What is your Hobby")
Color = input("What is your favorite Color?")
print ("Ah, so your Name is %s, your Hobby is %s,and your favorite Color is %s. " % (Name, Hobby, Color))
或者我会建议你使用string.format
至少使用它我觉得更容易。
print ("Ah, so your Name is {0}, your Hobby is {1},and your favorite Color is {2} .".format(Name, Hobby, Color))
输出
What is your Name?toheed
What is your Hobbycricket
What is your favorite Color?blue
Ah, so your Name is toheed, your Hobby is cricket,and your favorite Color is blue.