如果声明没有调用函数

时间:2016-05-15 19:22:25

标签: python if-statement

出于某种原因,我的if语句不会做它的意图。我不确定为什么我确定我已经正确格式化了。

def attack():
    os.system('clear')
    pAttack=random.randint(playerIG.attack/2, playerIG.attack)
    eAttack=random.randint(enemy.attack/2, enemy.attack)
    if pAttack==playerIG.attack/2:
        print "You miss!"
    else:
        enemy.health-=pAttack
        print "You deal %s damage" % pAttack
    option=raw_input("")
    if enemy.health<=0:
        win()
    os.system('clear')
    if eAttack==enemy.attack/2:
        print "The enemy missed!"
    else:
        playerIG.health-=eAttack
        print "The enemy deals %s damage" % eAttack
    option=raw_input("")
    if playerIG.health<=0:
        die()
    else:
        fight()

我们正在关注的部分是:

if enemy.health<=0:
        win()

我不确定为什么,但即使敌人的健康状况低于零,它也不会调用win()。

赢取功能:

def win():
    print "You have successfully killed the %s!" % enemy.name
    print "You have gained %s gold!" % enemy.goldgain

任何解决方案都会有所帮助,谢谢!

1 个答案:

答案 0 :(得分:3)

您在os.system('clear')之后立即致电win(),因此您无法看到获胜讯息。