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
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper insd. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €4,49. Je zit daarna nergens aan vast.