Проблема с кодом.Уровень для меня очень сложный

Пожалуйста, скопируйте и вставите свой новый код?

English

Will you please copy and paste your new code?

2 Likes

Новый код ещё не написал,если вы имеете ввиду старый код,то скину:

def findOfCoins(coins):
    coinIndex=0
    coinAmount=0
    while coinIndex<len(coins) :
    coinAmount+=coins[coinIndex].value
    coinIndex+=1

def collectOfCoins():
     coinAmount=0
     coinIndex=0
     while coinIndex<len(coins):
           coinAmount+=coins[coinIndex].value
           coinIndex+=1

def saveOfMyLife():
      enemy=hero.findNearestEnemy()
      if enemy:
          hero.moveXY(5,49)
          hero.moveXY(5,20)
          hero.moveXY(76,51)
          hero.moveXY(77,19)
     else:
         collectOfCoins()

while True:
    coins=hero.findNearest(hero.findItems())
    coin=hero.findItems()
    if coin:
        if coin.value<=150:
            findOfCoins(coins)
            collectOfCoins()
        else:
            saveOfMyLife()
    continue

Why is my programme not work?

Думаю, я знаю, в чем проблема, но не могли бы вы опубликовать свой код, чтобы я мог ответить на конкретную часть?

I think I know what the problem is, but can you please post your code so I can reply to the specific piece?

1 Like

@PeterPalov, he’s passing this level, but he’s not putting spaces in between things like if : and while :. Why is this? I am asking you, because you are also Russian and did CoCo.

PeterPalov, он проходит этот уровень, но он ставит пробелы между такими вещами, как если и пока :. Почему это? Я спрашиваю тебя, потому что ты тоже русский и сделал CoCo

Screenshot 2021-08-13 21.46.36

В этом нет необходимости, вместо этого следует использовать hero.gold.
Должно получиться так:

This isn’t needed, hero.gold should be used instead.
It should be like:

def createOfSoldier():
     if hero.gold() >= 20:
          hero.moveXY(84, 51)

Screenshot 2021-08-13 21.50.30

Это тоже следует исправить. Вы вызываете эту функцию в цикле while true, поэтому цикл while внутри функции не нужен.

Его можно сократить до:

This should also be fixed. You are calling this function in a while true loop, so there isn’t a need for the while loop inside the function.

It can be shortened to:

def collectOfCoins():
     coin = hero.findNearestItem()
     if coin:
         hero.move(coin.pos)

Lol, I do not think that’s the problem. Also, I do not know why there are spaces, and that doesn’t connect to the keyboard or something.

2 Likes

I mean he isn’t :woman_facepalming: You are supposed to put spaces in between.