[Reserved] Netease Wars geeks Official Guide - Dungeon - Lost in the stacks

Connection points:

https://codecombat.163.com/play/level/lost-in-the-stacks

Using the code block to find a way out of the library.

Summary:

So far, your code is running in accordance with the order.

Now, you will use code blocks: command set can be used repeatedly.

This is the way how you have to create a code block:

# Code block starts at:
while True:
    # Then, any command by the four spaces are indented portion of the code block.
    hero.moveRight ()
    hero.moveUp()
    hero.moveLeft()
    hero.moveDown()

All movement commands are part of the block of code.

while-true command statement: Repeating code blocks over and over again in order.

The default code

# Cycle repeated piece of code.
A code block # indented four spaces.
From the start block # colon:
while True:
    # Move to indent list!
    # Add four spaces to the beginning of each line, as well as:
    hero.moveRight ()
hero.moveUp ()  # delta indent this line
hero.moveLeft ()  # delta indent this line
hero.moveDown ()  # delta indent this line

Overview

Code block is really very useful!

Make sure you have mastered this, you will be very dependent on them in the future checkpoints inside!

In this cycle the level while-true command

while True:
    hero.say ( "Start Here")
    hero.say ( "then declare this.")
    hero.say ( "jump starting line again now!")

He tells the program to repeat over and over again inside the block of code!

Lost in the stacks Solution

# Cycle repeated piece of code.
A code block # indented four spaces.
while True:
    # Move to indent list!
    # Add four spaces to the beginning of each line, as well as:
    hero.moveRight ()
    hero.moveUp ()  # this line indent
    hero.moveLeft ()  # delta indent this line
    hero.moveDown ()  # delta indent this line
 

Raiders made in the official teaching Wars geeks column, the original address is:

https://codecombat.163.com/news/jikezhanji-mishizaishuku

Geek Wars - learn programming, with play!

Guess you like

Origin www.cnblogs.com/codecombat/p/12085302.html