Midterm#

1. Wie liegt?#

Jeff zegt: “Alice liegt of Jeff spreekt de waarheid” Bob zegt: “Jeff of Alice spreekt de waarheid” Alice zegt: “Karen liegt en Alice en Jeff spreken de waarheid” Karen zegt: “Bob en Alice spreken de waarheid”

  • a Jeff en Bob

  • b Bob en Alice

  • c Alice en Karen

  • d Karen en Jeff

2. Welke waarde heeft x aan het einde van dit programma?#

max_punten = 100
score = 30
x = score/max_punten * 9 + 1
score = 50

  • a 50

  • b 2.7

  • c 5.5

  • d 0.3

3. Welke waarde heeft x aan het einde van dit programma?#

x = 4
if x > 2 :
    x = x / 4
elif x < 2 :
    x = x + 3
else :
    x = x * 3
  • a 4

  • b 12

  • c 1

  • d 7

4. Welke waarde heeft x aan het einde van dit programma?#

x = 8
if x > 5 :
    x = x - 4
if x <= 4 :
    x = x + 3
elif x == 7 or x == 4 :
    x = x * 2
  • a 14

  • b 7

  • c 4

  • d 8

5. Wat print dit programma?#

x = "Emily"

if x < "E":
    print ("groep 1")
elif x < "M":
    print ("groep 2")
elif x < "Z":
    print ("groep 3")
else:
    print ("groep 4")

  • a ‘Groep 1’

  • b ‘Groep 2’

  • c ‘Groep 3’

  • d ‘Groep 4’

6. Wat print dit programma?#

woord = "Hanzehogeschool"
print(woord[-1])
  • a ‘H’

  • b ‘a’

  • c ‘l’

  • d ‘o’

7. Wat print dit programma?#

woord = "Hanzehogeschool"
print(woord[3:6])
  • a ‘’nze’

  • b ‘nzeh’

  • c ‘zeh’

  • d ‘zeho’

8. Wat print dit programma?#

woord = "Hanzehogeschool"
print(woord[-1:1:-2])
  • a ‘loceoen’

  • b ‘azhgsho’

  • c ‘Hneoecol’

  • d ‘’

9. Wat print dit programma?#

print(function(5, 10))

def function(x, y):
    if x <= y:
        return x
  • a 5

  • b 10

  • c None

  • d programma werkt niet

10. Wat print dit programma?#

def function(x, y):
    if x > y:
        return x
    return y

print(function(5, 10))
  • a 5

  • b 10

  • c None

  • d programma werkt niet

11. Wat print dit programma?#

def main():
    temp = function(10, 5)
    print(temp)


def function(x, y):
    if x < y:
        return x

main()
  • a 5

  • b 10

  • c None

  • d programma werkt niet

12. Wat print dit programma?#

def main():
    temp = function1(10, 5)
    print(temp)


def function1(x, y):
    if x < y:
        return function2(x)
    return function2(y)

def function2(x):
    return x * x

main()
  • a 5

  • b 10

  • c 25

  • d 100 e. None f. programma werkt niet

13. Wat print dit programma?#

def main():
    temp = function1(5, 12)
    print(temp)


def function1(x, y):
    if x % 2 == 0:
        x = x/2
    return x
    if x < y:
        return x
    return y

main()
  • a 5

  • b 12

  • c None

  • d Programma werkt niet

14. Hoe vaak print dit programma “hoi” ?#

def function(y):

    print("hoi")

    if y == 0:
        return

    function(y-1)

function(4)
  • a 3

  • b 4

  • c 5

  • d Programma werkt niet

15. Wat print dit programma?#

def function(x):

    if x == 0:
        return x
    print(function(x-1))
    return x

function(5)
  • a 1,2,3,4,5

  • b 0,1,2,3,4

  • c 5,4,3,2,1

  • d 4,3,2,1,0

16. Wat print dit programma?#

def function(x, y):

    print(x[y])

    if y == 0:
        return

    function(x, y-1)
    print(y)


function("Hanze", 4)
  • a H, 0, a, 1, n, 2, z, 3, e, 4

  • b H, a, n, z, e, 4, 3, 2, 1, 0 c, e, z, n, a, H, 4, 3, 2, 1, 0

  • d e, z, n, a, H, 4, 3, 2, 1 e. H, a, n, z, e, 4, 3, 2, 1 f. e, 4, z, 3, n, 2, a, 1, H

17. Wat print dit programma?#


def function(x):
    if len(x) == 0:
        return
    function(x[:-1])
    print(x[-1])

function("Hanze")
  • a H, a, n, z, e

  • b e, z, n, a, H

  • c H, H, H, H, H

  • d H, a, n, z

18. Welke error geeft dit programma?#

def function(x):

    print(x[0])

    if len(x) == 0:
        return

    function(x[:-1])

function("Hanze")
  • a IndexError

  • b RecursionError

  • c TypeError

  • d SyntaxError

19. Gegeven de volgende regels aan code.#

1function([1,2,3,4,5], 4)
2def function(x,y):
3    function(x[:-1], y-1)
4    if y == 0:
5    print(x[0:y])
6        return

In welke volgorde moeten deze regels staan om de volgende output te krijgen: [1, 2, 3, 4] [1, 2, 3] [1, 2] [1]

  • a 1, 2, 5, 4, 6, 3

  • b 2, 4, 5, 6, 3, 1

  • c 1, 2, 4, 6, 5, 3

  • d 2, 5, 4, 3, 6, 1

20. 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 printstatement moet er op regel 4 komen om de volgende output te generen ?

   xxxx
  xxxxxx
 xxxxxxxx
 -  **a** print(y*' ' + x*y)
 -  **b** print(y*' ' + x*y*2)
 -  **c** print((z-y)*' ' + x*y*2)
 -  **d** print((z-y)*' ' + x*y)