In dit document vind je alle oefeningen met de daarbij horende oplossingen terug samengevat in 1 enkel document. De oefeningen betreffen alle wpo's gezien in het academiejaar met assistent Mathias Hanson.
My electricity bills for the last three months have been € 23, € 32 and € 64. What
is the average monthly electricity bill over the three-month period? Write an
expression to calculate the mean, and use print() to view the result.
# Write an expression that calculates the average of 23, 32 and 64
# Place the expression in this print statement
print((23 + 32 + 64)/3)
Calculations for a tiler
Two parts of a floor need tiling. One part is 9 tiles wide by 7 tiles long, the
other is 5 tiles wide by 7 tiles long. Tiles come in packages of 6.
- How many tiles are needed?
- You buy 17 packages of tiles containing 6 tiles each. How many tiles will be left
over?
# Fill this in with an expression that calculates how many tiles are needed.
print(9*7 + 5*7)
# Fill this in with an expression that calculates how many tiles will be left over.
print(17*6 - (9*7 + 5*7))
1
,Assign and Modify Variables
After each comment write a line of code that implements the instruction.
Note that this code uses scientific notation to define large numbers. 4.445e8 is
equal to 4.445 * 10 ** 8 which is equal to 444500000.0.
# The current volume of a water reservoir (in cubic metres)
reservoir_volume = 4.445e8
# The amount of rainfall from a storm (in cubic metres)
rainfall = 5e6
# decrease the rainfall variable by 10% to account for runoff
rainfall *= .9
# add the rainfall variable to the reservoir_volume variable
reservoir_volume += rainfall
# increase reservoir_volume by 5% to account for stormwater that flows
# into the reservoir in the days following the storm
reservoir_volume *= 1.05
# decrease reservoir_volume by 5% to account for evaporation
reservoir_volume *= 0.95
# subtract 2.5e5 cubic metres from reservoir_volume to account for water
# that's piped to arid regions.
reservoir_volume -= 2.5e5
# print the new value of the reservoir_volume variable
print(reservoir_volume)
2
,Which is denser, Rio or San Francisco?
Try comparison operators in this quiz! This code calculates the population
densities of Rio de Janeiro and San Francisco.
Write code to compare these densities. Is the population of San Francisco more
dense than that of Rio de Janeiro? Print True if it is and False if not.
# Write code that prints True if San Francisco is denser than Rio, and False otherwise
print(san_francisco_pop_density > rio_de_janeiro_pop_density)
# Note: other solutions are possible, like the one below, but take a moment to make sure
you understand and appreciate the concise efficiency of the one line above!
if (san_francisco_pop_density > rio_de_janeiro_pop_density):
print (True)
else:
print (False)
3
, Write a Server Log Message
Youve learned to print a log message like this one (with the username, url, and timestamp
replaced with values from the appropriate variables):
John.McAfee accessed the site https://canvas.vub.be/courses/234097 at 12:53.
# TODO: print a log message using the variables above.
print (username + " accessed the site " + url + " at " +
timestamp + ".")
Use string concatenation and the len() function to find the length of a certain
movie star's actual full name. Store that length in the name_length variable.
Don't forget that there are spaces in between the different parts of a name!
# TODO: calculate how long this name is of name_length
name_length = len(given_name + " " + middle_names + " " +
family_name)
name_length = len(given_name) + len(middle_names) +
len(family_name) + 2
# Now we check to make sure that the name fits within the driving license character limit
# Nothing you need to do here
driving_license_character_limit = 28
print(name_length <= driving_license_character_limit)
4
Les avantages d'acheter des résumés chez Stuvia:
Qualité garantie par les avis des clients
Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.
L’achat facile et rapide
Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.
Focus sur l’essentiel
Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.
Foire aux questions
Qu'est-ce que j'obtiens en achetant ce document ?
Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.
Garantie de remboursement : comment ça marche ?
Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.
Auprès de qui est-ce que j'achète ce résumé ?
Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur insd. Stuvia facilite les paiements au vendeur.
Est-ce que j'aurai un abonnement?
Non, vous n'achetez ce résumé que pour €4,49. Vous n'êtes lié à rien après votre achat.