Ad

Objective

Write a function which returns a multi-line string that contains an ASCII representation of a caterpillar.

The caterpillar is determined by zero or more segments, and each segment can have zero or more pairs of legs.

Examples

Caterpillar with one segment and two pairs of legs per segment:

\_/__ 
(")oo)
   ^^

Caterpillar with two segments with two pairs of leg for each:

\_/__ __
(")oo)oo)
   ^^ ^^

Caterpillar with two segments with four pairs of legs for each:

\_/____ ____
(")oooo)oooo)
   ^^^^ ^^^^

A poor caterpillar without any segments (poor you!):

\_/
(")

Precision

  • No trailing spaces.
  • The return string must have 3 lines.
def caterpillar(segments, legpairs):
    pass