Skip to main content
Level 01: inputs, outputs and structure 0 of 9 activities solved
  1. 1. Hello World Not yet solved
  2. 2. Carpet cost Not yet solved
  3. 3. Ball pit Not yet solved
  4. 4. Dice face 5 Not yet solved
  5. 5. Temperature converter Not yet solved
  6. 6. Fish tank volume Not yet solved
  7. 7. Microscopy Not yet solved
  8. 8. Circle properties Not yet solved
  9. 9. Energy bill calculator Not yet solved
Next series Level 02: selections
Level 01: inputs, outputs and structure

3. Ball pit

Sign in to hand in your solution and get feedback.

# 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.")