Reading code#
Opdracht 1#
Welke error geeft onderstaande code?
def function(x):
print(x[0])
if len(x) == 0:
return
function(x[:-1])
function("Hanze")
Opdracht 2#
Wat is de output van onderstaande programma?
def function(x):
if len(x) == 0:
return
function(x[:-1])
print(x[-1])
function("Hanze")
Opdracht 3#
Gegeven de volgende regels aan code
1def function(x,y,z):
2 if y == z:
3 return
4
5 function(x, y+1, z)
6
7function("x", 2, 5)
Welke print statement moet er op regel 4 komen om de volgende output te generen?
xxxx
xxxxxx
xxxxxxxx
Opdracht 4#
Wat is de output van onderstaande programma?
def main():
x = [1,7,3,8,9,5]
function(x)
print(x)
def function(x):
if len(x) <= 1:
return
x[0] = function2(x[0], x[1])
function(x[1:])
def function2(x, y):
if x < y:
return x
return y
main()