Warning! It seems that you are using Dodona within another webpage, so not everything may work properly. Let your teacher know so that he can solve the problem by adjusting a setting in the learning environment. In the meantime, you can click this link to open Dodona in a new window.
Warning! The page was not fully loaded, probably because of a network issue. It could be that not all functionalities work as expected. Please try reloading the page.
# Ball pit program
# -------------------------
# Subprograms
# -------------------------
# Function to return the volume of the ball pit
def ball_pit_volume(ball_pit_radius, ball_pit_height):
pi = 3.14
return pi * (ball_pit_radius * ball_pit_radius) * ball_pit_height
# Function to return the volume of a ball
def ball_volume(ball_radius):
pi = 3.14
return (4 / 3) * pi * (ball_radius * ball_radius * ball_radius)
# -------------------------
# Main program
# -------------------------
ball_pit_radius = 1 # Meters
ball_pit_height = 0.2 # Meters
ball_radius = 0.05 # Meters
packing_density = 0.75 # Volume taken up by the balls
balls = (ball_pit_volume(ball_pit_radius, ball_pit_height) / ball_volume(ball_radius)) * packing_density
print("You need", balls, "balls to fill the ball pit.")
Python sandbox
This window allows you to run Python code without installing a thing. The code you write here is not automatically submitted to Dodona.