PYTHON LESSON

Topic 43/63 · Phase 5: Object-Oriented Programming

Polymorphism — Python lesson on EduBard (phase: Object-Oriented Programming)

Polymorphism

Main idea

Different classes respond to same method name differently.

Tip

Code to interface not type checks.

Watch out

if-type chains everywhere.

Read this next

You will study Polymorphism. It belongs to the Object-Oriented Programming phase.

Remember this:
Different classes respond to same method name differently.

Practice step by step. Do not rush. Each run should show you something new.

Tip:
Code to interface not type checks.

Avoid this:
if-type chains everywhere.

Your challenge:
Shape area function calling area() polymorphically.

Go to the challenge lab below. Fix errors until the output looks right. Then press the green button to complete the topic.

Example code

Copy this example if it helps. Change it so it matches Polymorphism.

# Topic: Polymorphism
def main():
    sample = "edit me"
    # TODO: apply Polymorphism concept here
    result = sample
    print("Result:", result)

if __name__ == "__main__":
    main()

Challenge

Shape area function calling area() polymorphically.

Before you can finish: your output should include at least 16 characters; at least 1 non-empty line(s); no crash traceback—fix errors until the program runs cleanly.

Use Run. Read the output. Change your code until the task is done.

Starter reference

# Challenge starter for Polymorphism
def solve():
    # Write your solution here
    pass

print("Update solve() and run")

Your code

The first Run may load Python in your browser (one-time). Later runs are faster.



    
    

Navigation