Python的笑话或聊天错误
问题描述:
当我运行这个,如果我键入聊天它从上面的笑话运行punchline如何解决这个问题? enter image description herePython的笑话或聊天错误
print ("whats your name?")
firstname = input()
print ("hello,", firstname)
print ("what's your surname?")
surname = input()
fullname = (firstname +" "+ surname)
print ("hello,", fullname)
print ("what shall i call you on a daily basis?")
name = input()
print ("Glad to meet you,", name)
print ("is there anything you would like to do?")
print (" you can 'hear a joke' or 'have a chat'")
question = input("joke or chat?")
if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("Dead!!! LOL!!!!")
if question == "chat":
print("what games do you like?")
game = input()
print ("NO way i love,", game)
答
你间距/压痕熄灭:
if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("Dead!!! LOL!!!!")
在你的代码应该是:
if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("Dead!!! LOL!!!!")
PS:你应该使用超过1个空间缩进到使它更易于阅读。如:
if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("Dead!!! LOL!!!!")
+0
Python建议使用4个空格作为缩进。 –
答
在没有适当的缩进的,Python是假设线
idk = input()
print ("Dead!!! LOL!!!!")
是if
声明之外。缩进他们就像你为print
声明所做的一样。
看起来它正在做它应该做的事情,但我很惊讶它甚至会在缩进时运行。由于python没有大括号,正确缩进块。 – Li357
哪个版本的python? –