Opstap¶
Syntax van functies¶
Leerdoel: het lezen van functies
Opdracht 1¶
def main():
"""
Main functie. Roept de andere functies aan om hun werk te doen.
"""
x = function(4) + function(6)
print(x)
def function(x):
lst = list(range(x))
return sum(lst)
main()
a. Wat doet de functie function?
b. Wat is de output van dit programma?
c. Gebruik Python Tutor of de cellen op deze pagina om je antwoord op a en b te controleren.
# controleer jouw antwoord
Opdracht 2¶
def main():
"""
Main functie. Roept de andere functies aan om hun werk te doen.
"""
x = function("lol")
y = function("xo")
print(x + y)
def function(x):
s = x[::-1] + x
return s
main()
a. Wat doet de functie function?
b. Wat is de output van dit programma?
c. Gebruik Python Tutor of de cellen op deze pagina om je antwoord op a en b te controleren.
# controleer jouw antwoord
Opdracht 3¶
def main():
"""
Main functie. Roept de andere functies aan om hun werk te doen.
"""
L = function1(5)
x = function2(L)
print(x)
def function1(x):
L = list(range(x))
return L[::-1]
def function2(L):
x = sum(L)
y = len(L)
return x / y
main()
a. Wat doet de functie function1?
b. Wat doet de functie function2?
c. Wat is de output van dit programma?
d. Gebruik Python Tutor of de cellen op deze pagina om je antwoord op a, b en c te controleren.
# controleer jouw antwoord