2014-10-16 113 views
0
import random 

import time 
def header(): 
    printNow("The program is starting now, prepare to be slain") 
    monsterTest(); 
def monsterTest(): 
for i in range(0,1): 
    currentHp = 99; 
    printNow("Starting Health is: "+str(currentHp)) 
    randomHit = random.randint(0,50) 
    attack1 = currentHp - randomHit 
    printNow("Monster attacks for: "+str(randomHit)) 
    printNow("Remaining Health is: "+str(currentHp-randomHit)) 
    battle1 = attack1 
    printNow(">>>") 
    printNow("Next Attack Incoming!") 
    printNow(">>>") 
    time.sleep(1.5) 
    currentHp = battle1 
    printNow("Current Health is: "+str(currentHp)) 
    attack2 = currentHp - randomHit 
    printNow("Monster attacks again for: "+str(attack2)) 
    battle2 = currentHp - attack2 
    printNow("After That we are left with "+str(battle2)+" HP") 
footer(); 


def footer(): 
    printNow(">>>") 
    printNow("Thank you for using Cidadel's Battle Simulator, this concludes our test...") 

printNow(header()) 

The program is starting now, prepare to be slain 
Starting Health is: 99 
Monster attacks for: 38 
Remaining Health is: 61 
>>> 
Next Attack Incoming! 
>>> 
Current Health is: 61 
Monster attacks again for: 23 
After that we are left with 38 HP 
>>> 
Thank you for using Citadel's Battle Simulator, this concludes our test... 
*None* 
>>> 

爲什麼我會得到這個沒有,我認爲這與我的printNow命令做的,但我不知道我在做什麼錯誤使實際無值..:/爲什麼我得到None的值?

我試圖只是運行正常,但我始終得到無值我上去列表註釋掉我行

+1

什麼是'printNow()'? – IanAuld 2014-10-16 23:57:49

回答

2

當你這樣做:

printNow(header()) 

header()的結果傳遞給printNow,它顯然會打印它,因爲header()返回None,這是由於在每個函數結束時隱含的return None

替換與剛剛header一個電話:

header() 
+0

非常感謝:)真的有幫助..當你說我通過標題通過我做了很好的'ol facepalm – 2014-10-17 00:12:42