03. Quiz: Defining Functions
Lots of Practice
An excellent resource for putting your skills to use is to join communities like the one at HackerRank. Here you can work through tons of problems at your own pace! Once you master writing functions, you will be ready to build full applications using Python.
Quiz: Population Density Function
Write a function named population_density
that takes two arguments, population
and land_area
, and returns a population density calculated from those values. I've included two test cases that you can use to verify that your function works correctly. Once you've written your function, use the Test Run button to test your code.
Start Quiz:
# write your function here
# test cases for your function
test1 = population_density(10, 1)
expected_result1 = 10
print("expected result: {}, actual result: {}".format(expected_result1, test1))
test2 = population_density(864816, 121.4)
expected_result2 = 7123.6902801
print("expected result: {}, actual result: {}".format(expected_result2, test2))
Quiz: readable_timedelta
Write a function named readable_timedelta
. The function should take one argument, an integer days
, and return a string that says how many weeks and days that is. For example, calling the function and printing the result like this:
print(readable_timedelta(10))
should output the following:
1 week(s) and 3 day(s).
Start Quiz:
# write your function here
# test your function
print(readable_timedelta(10))