-
Notifications
You must be signed in to change notification settings - Fork 0
2024_2025_deeltoets_1
Harry Broeders edited this page Mar 5, 2025
·
3 revisions
De opgaven kun je vinden op: https://bitbucket.org/HR_ELEKTRO/ems10/wiki/Toetsen/2024-2025_Deeltoets_1.pdf
def schuifLetter(letter, n):
return chr(ord('A') + ((ord(letter.upper())-ord('A') + n) % 26))
# Testen van de functie
print(schuifLetter('A', 1))
# Verwachte uitvoer: BEen uitgebreidere test is hieronder gegeven:
if schuifLetter('A', 1) == 'B' and
schuifLetter('A', 15) == 'P' and
schuifLetter('A', 26) == 'A' and
schuifLetter('A', 0) == 'A' and
schuifLetter('Z', 2) == 'B':
print('schuifLetter werkt zoals verwacht')
else:
print('schuifLetter werkt niet zoals verwacht')def schuifWoord(woord, n):
opgeschoven = ''
for letter in woord:
opgeschoven += schuifLetter(letter, n)
return opgeschovenAlternatieve (minder handige) oplossing:
def schuifWoord(woord, n):
opgeschoven = ''
for index in range(len(woord)):
opgeschoven += schuifLetter(woord[index], n)
return opgeschovenDeze functie kan als volgt getest worden:
# Testen van de functie zoals gegeven in opgave 1B
print(schuifWoord("HALLO", 3))
print(schuifWoord("ZOEMER", 1))woord = input('Welk voord wil je opschuiven?')
n = input('Hoeveel letters wil je het woord opschuiven?')
print(schuifWoord(woord, int(n)))def isVerschuiving(woord1, woord2):
for i in range(1, 27):
if woord1.upper() == schuifWoord(woord2, i):
return True
return FalseDeze functie kan als volgt getest worden:
# Testen van de functie zoals gegeven in opgave 1D
print(isVerschuiving('HALLO', 'KDOOR'),
isVerschuiving('TEST', 'GHTY'),
isVerschuiving('HALLO', 'HALLO'))lijst = [7, -12, 9, -3.9, -8, -0.0]
som = 0
for element in lijst:
if element < 0:
som += element
print(som)Alternatieve oplossing:
lijst = [7, -12, 9, -3.9, -8, -0.0]
negatieve_getallen = []
for element in lijst:
if element < 0:
negatieve_getallen.append(element)
print(sum(negatieve_getallen))lijst = [7, -12, 9, -3.9, 'Test', -8, -0.0, '-1']
som = 0
for element in lijst:
if isinstance(element, int) or isinstance(element, float):
if element < 0:
som += element
print(som)De twee if-statements kunnen samengevoegd worden:
lijst = [7, -12, 9, -3.9, 'Test', -8, -0.0, '-1']
som = 0
for element in lijst:
if (isinstance(element, int) or isinstance(element, float)) and element < 0:
som += element
print(som)De twee isinstance-functie-aanroepen kunnen samengevoegd worden:
lijst = [7, -12, 9, -3.9, 'Test', -8, -0.0, '-1']
som = 0
for element in lijst:
if isinstance(element, (int, float)) and element < 0:
som += element
print(som)Je kunt ook de type-functie gebruiken:
lijst = [7, -12, 9, -3.9, 'Test', -8, -0.0, '-1']
som = 0
for element in lijst:
if (type(element) == int or type(element) == float) and element < 0:
som += element
print(som)