您的位置首页百科知识

极客战记 沙漠--许愿井

极客战记 沙漠--许愿井

的有关信息介绍如下:

极客战记 沙漠--许愿井

网易《极客战记》是一款在线的寓教于乐的编程教育产品。产品通过循序渐进的游戏过程,让用户在不知不觉中掌握编程技能,更培养他们迎难而上的精神和团队协作能力。

选择关卡

选择英雄装备

写代码

# 你需要104的金钱,不多也不少。

less = "Nimis"more = "Non satis"requiredGold = 104

# 此函数计算所有的硬币值的总和。def sumCoinValues(coins): coinIndex = 0 totalValue = 0 # 遍历所有的金币。 while coinIndex < len(coins): totalValue += coins[coinIndex].value coinIndex += 1 return totalValue

def collectAllCoins(): item = hero.findNearest(hero.findItems()) while item: hero.moveXY(item.pos.x, item.pos.y) item = hero.findNearest(hero.findItems())

while True: items = hero.findItems() # 获得硬币的总值 goldAmount = sumCoinValues(items) # 如果有金币,那么金币数目 (goldAmount) 不会是零 if goldAmount != 0: # If goldAmount is less than requiredGold # 那就说“Non satis” if goldAmount < requiredGold: hero.say("Non satis") # If goldAmount is greater than requiredGold # 那么说出“Nimis”。 if goldAmount > requiredGold: hero.say("Nimis") # 如果 “goldAmount” 等于 “requiredGold” # 如果有刚好 104 金币,就全部收集。 if goldAmount == requiredGold: collectAllCoins() pass

提交

通关