home
Go back to the centre, facing right.
home()forward(80)
left(90)
forward(40)
home()
Web apps with Flask · In any playground, open Reference to copy these.
Go back to the centre, facing right.
home()forward(80)
left(90)
forward(40)
home()
Give a value a name, so you can reuse and change it.
size = 50length = 120
forward(length)
left(90)
forward(length / 2)
Keep many values in order under one name. The first item is place 0.
colours = ["red", "blue", "green"]Work through a list, one item at a time.
for c in colours:
passpensize(6)
for c in ["red", "blue", "green"]:
pencolor(c)
forward(40)
Join pieces of text into one with +. Spaces only appear where they are inside the quotes.
"Hello, " + nameThe value stored under that key. The key goes in quotes. Assign to it to change it: star["speed"] = 8.
star["speed"]True if the item is in the list (or the key is in the dictionary, or the letters are in the text).
if item in bag:
passA template is HTML with gaps: {{ }} shows a value, {% for %} repeats a part for each item.
PAGE = """<ul>
{% for m in members %}
<li>{{ m["name"] }}</li>
{% endfor %}
</ul>"""
return render_template_string(PAGE, members=members)Do one thing or the other, depending on a condition.
if x > 0:
pass
else:
passfor x in [-90, -30, 30, 90]:
penup()
goto(x, 0)
if x > 0:
dot(30, "red")
else:
dot(30, "blue")
hideturtle()
Change a value every pass: read the old one, store a new one.
size = 5
for i in range(20):
forward(size)
right(90)
size = size + 5size = 5
for i in range(30):
forward(size)
right(90)
size = size + 5
Name a group of steps, then run it by calling its name.
def shape():
pass
shape()def zigzag():
left(45)
forward(30)
right(90)
forward(30)
left(45)
zigzag()
zigzag()
zigzag()
Joins an address to a function. What the function returns is the page.
@app.route("/about")
def about():
return "<h1>About</h1>"<name> matches any word in that place of the address, and is passed to the function.
@app.route("/group/<name>")
def group(name):
return "You asked for + name