Stage 5 · Bellows Bridge
Functions & return
“A spell that returns nothing builds nothing, little ember.”Bellows Sage
Scrolls on the trail
These are the 5 lore scrolls you'll find in Bellows Bridge, in the order the lesson teaches them. The comment after each print shows what it outputs.
Lore scroll · Functions & return
Naming a Spell
def double(n):
return n * 2
print(double(4)) # 8
print(double(10)) # 20def names a block of code. Calling double(4) runs it with n set to 4.
Lore scroll · Functions & return
Handing Back
def shout(word):
return word.upper()
loud = shout("ash")
print(loud + "!") # ASH!return hands a value back to the caller, to store in a name or use at once.
Lore scroll · Functions & return
Nothing Returned
def hum():
print("mm") # mm
print(hum()) # Noneprint shows a value but hands nothing back. With no return, a call gives None.
Lore scroll · Functions & return
Default Arguments
def heat(n, by=2):
return n + by
print(heat(5)) # 7
print(heat(5, 10)) # 15by=2 is a default: used when the call leaves it out, replaced when it doesn't.
Lore scroll · Functions & return
Inside Stays Inside
x = 1
def bump():
x = 9
return x
print(bump(), x) # 9 1A name set inside a function is its own. The x outside is left alone.
The stage puzzle: The span bridge
The chasm is fourteen tiles wide, too far for any jump. Four call blocks marked 3, 4, 5 and 6 hang before the edge. Bumping one calls span with that number and lays a plank bridge as long as the value it returns. Too short and the planks fall into the chasm. Too long and they hit the far cliff and break.
def span(n):
return n * 2 + 4
bridge = span(?) # gap 14Show the answer
span(5) returns 5 * 2 + 4 = 14, the exact width of the gap.
Practice the Bellows Sage's trial
In the game, the Bellows Sage duels you in a sealed arena. His question shows across the top of the screen, and you answer by jumping up into the lettered block, A to D, while you dodge his spells. You need 4 right answers to banish him. These are his questions, drawn from all 11 in his bank. The hints work the same as in the game: ask once for his riddle, and ask again for him to rule out a wrong answer.