Python笑话或聊天错误

时间:2016-09-14 21:43:53

标签: python

当我运行这个时,如果我输入聊天它会从笑话中运行一个妙语如何解决这个问题? enter image description here

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)

2 个答案:

答案 0 :(得分:1)

您的间距/缩进已关闭:

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!!!!")

答案 1 :(得分:1)

在没有适当缩进的情况下,Python假定行

idk = input()
print ("Dead!!! LOL!!!!")

if语句之外。缩进它们就像你为妙语的print语句所做的那样缩进。