Sign in
or
Register
Courses
Textbook
Compiler
Contests
Topics
Courses
Python. Robot
Python. Robot. Loop "repeat N times"
Module:
Python. Robot. Loop "repeat N times"
1
/6.
Repeat N times
Get the robot to the base. Write a program using no more than 2 lines of code!
Type your program below
C++
Python
To check the solution of the problem, you need to register or log in!
Previous Submissions
Silversmith
×
Loop with a known number of repetitions "
repeat N:
"
If you need to execute some sequence of the same commands
N
times in the program, then to shorten the code, use the construction:
repeat N:
commands
For example, program:
forward
forward
forward
forward
you can write shorter:
repeat 4:
forward
Such a construction is called a
loop with a known number of repetitions
. The use of loops in the program significantly reduces the size of the program, and hence the memory occupied by the program.
Loops is a key concept in computer science. If you want to be a good programmer, knowing how to handle loops is the most important skill to learn.
In order to show the robot which commands to repeat,
indent 4 spaces from the beginning of the line
!
Indentation is very important in Python. By indenting, we define a certain block of commands that must be executed in a loop, or after checking the condition.
Result
×