Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Implement a Simple Multiple Inheritance Example

Practice multiple inheritance by combining Animal and Machine behaviors into a RoboDog class.

Python practice15 minInheritance & PolymorphismIntermediateLast updated April 8, 2026

Problem statement

You will implement a small class hierarchy that demonstrates multiple inheritance. Two base classes are provided: Animal (which knows a name and can speak) and Machine (which has a serial number and a battery level that can be charged). Implement a RoboDog class that inherits from both Animal and Machine. RoboDog should: - Initialize both parent classes correctly. - Expose its serial number as an attribute. - Implement speak() to combine a robotic beep with a dog's bark (e.g. "Beep! Woof! I'm Rex"). - Implement charge(amount) to increase battery but never exceed 100 and ignore negative charge amounts. - Implement get_battery() to return the current battery level as an integer. Also provide a helper function create_robo(name, serial, battery) that returns an initialized RoboDog.

Task

Implement a class that inherits from two base classes, properly initializes both parents, and overrides/combines behavior.

Examples

Basic RoboDog speak

Input

create_robo("Rex", "RX1", 20).speak()

Output

Beep! Woof! I'm Rex

RoboDog combines a robotic beep with a bark and uses the Animal name.

Input format

The evaluator will call create_robo(name, serial, battery) and then call methods on the returned RoboDog in a single expression.

Output format

Return values from method calls or attribute access. For methods that return strings, return the exact string. For battery values return integers.

Constraints

- Battery is an integer between 0 and 100. - charge(amount) should not allow battery to go below 0 or above 100; negative amounts are ignored. - Use proper initialization so both base classes' __init__ are executed.

Samples

Sample 1

Input

r = create_robo("Bolt", "B2", 5); r.get_battery()

Output

5

The helper returns a RoboDog with battery 5.