2016-11-30 36 views
0

我正在爲我的朋友製作生日禮物。我正在製作一個有史以來每一個奇蹟角色的數據庫,到目前爲止我已經完成了其中的兩個,去測試它,它說錯誤。我已經看遍了所有的代碼,我已經嘗試了很多,但它似乎並沒有工作。這是代碼。努力在python中找到錯誤

from time import sleep 

print ("Welcome to the Marvel Database please input the name of a marvel character you want to research. Please make sure you type the name as accurately as possible.") 
character = input() 

if character == 'A-Bomb': 
    print ("loading", sleep(.5), ".", sleep(.5), ".", sleep(.5), ".") 
    print ("Character found.") 
    sleep(.5) 
    print ("Name is A-Bomb.") 
    sleep(1) 
    print ("Unknown if they or it are Hero or Villan.") 
    sleep(1) 
    print ("No infomation found.") 
    sleep(1) 

elif character == 'a-bomb': 
    print ("loading", sleep(.5), ".", sleep(.5), ".", sleep(.5), ".") 
    print ("Character found.") 
    sleep(.5) 
    print ("Name is A-Bomb") 
    sleep(1) 
    print ("Unknown if they or it are Hero or Villan.") 
    sleep(1) 
    print ("No infomation found") 
    sleep(1) 

elif character == 'a bomb': 
    print ("loading", sleep(.5), ".", sleep(.5), ".", sleep(.5), ".") 
    print ("Character found.") 
    sleep(.5) 
    print ("Name is A-Bomb") 
    sleep(1) 
    print ("Unknown if they or it are Hero or Villan.") 
    sleep(1) 
    print ("No infomation found") 
    sleep(1) 

elif character == 'A-bomb': 
    print ("loading", sleep(.5), ".", sleep(.5), ".", sleep(.5), ".") 
    print ("Character found.") 
    sleep(.5) 
    print ("Name is A-Bomb") 
    sleep(1) 
+7

什麼是錯誤? – dorukayhan

+0

您需要突出顯示您的代碼,並在將來使用「{}」按鈕。 –

+1

'print(sleep(0.5))'將打印'time.sleep()'的返回值,它總是'None'。並且請記住'print()'將在'print()'之前被評估,所以三重睡眠打印或多或少等於'sleep(1.5);打印(...)'。 – dhke

回答

2
from time import sleep 

print ("Welcome to the Marvel Database please input the name of a marvel character you want to research. Please make sure you type the name as accurately as possible.") 
character = input().lower() 

a_bomb_list = ["a-bomb", "a bomb"] 

if character in a_bomb_list: 
    print ("loading", sleep(.5), ".", sleep(.5), ".", sleep(.5), ".") 
    print ("Character found.") 
    sleep(.5) 
    print ("Name is A-Bomb.") 
    sleep(1) 
    print ("Unknown if they or it are Hero or Villan.") 
    sleep(1) 
    print ("No infomation found.") 
    sleep(1) 

你並不需要創建一個單獨的if每個排列,上面的代碼與「原子彈」或「炸彈」 :)的任何資本