2016-09-14 72 views
-3

當我運行這個,如果我鍵入聊天它從上面的笑話運行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) 
+0

看起來它正在做它應該做的事情,但我很驚訝它甚至會在縮進時運行。由於python沒有大括號,正確縮進塊。 – Li357

+0

哪個版本的python? –

回答

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

Python建議使用4個空格作爲縮進。 –

1

在沒有適當的縮進的,Python是假設線

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

if聲明之外。縮進他們就像你爲print聲明所做的一樣。