HomeTurtlegraficsGPanelRobotics WebTigerPython |
Python - Online |
Deutsch English |
YOU LEARN HERE... |
the important concept of variables. In computer science, variables are names that serve as placeholders for values that can change during program execution. |
EXAMLES |
Program: from gturtle import * makeTurtle() n = 7 setPenColor("blue") repeat n: forward(100) right(360 / n) ou can now easily draw any other n-corner, whereby you must also adjust the side length in each case so that the figure is not too large. You can even enter the values for n after starting the program. With the instruction
Program: from gturtle import * makeTurtle() setPenColor("blue") n = inputInt("Gib die Anzahl Ecken an:") repeat n: forward(500 / n) right(360 / n) The value of the variable can also change during the course of the program by reassigning it. For example, for the side length size of a square:
|
REMEMBER... |
A variable is created when you assign a value to it using the equals sign. You can change its value at any time with a new assignment and even use its own (old) value. You must not confuse the notation used with a mathematical equation. The program statement: n = n + 1 has nothing to do with a mathematical equation, i.e. with the task of determining n in such a way that the same value results to the left and right of equal signs. For n = n + 1 there is also the short form n += 1, which does exactly the same thing. |
TO SOLVE BY YOURSELF |
|