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
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller insd. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $4.87. You're not tied to anything after your purchase.