From 050c86f13b82ebd73614da163e9ea682e06b3356 Mon Sep 17 00:00:00 2001 From: Hilya Ntinda <113698301+Hilya02@users.noreply.github.com> Date: Mon, 6 Feb 2023 15:15:56 +0200 Subject: [PATCH] 101-add_attribute.py --- 0x0A-python-inheritance/101-add_attribute.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 0x0A-python-inheritance/101-add_attribute.py diff --git a/0x0A-python-inheritance/101-add_attribute.py b/0x0A-python-inheritance/101-add_attribute.py new file mode 100644 index 0000000..6ee534e --- /dev/null +++ b/0x0A-python-inheritance/101-add_attribute.py @@ -0,0 +1,13 @@ +#!/usr/bin/python3 +""" +adds an object +""" + + +def add_attribute(obj, name, value): + """ + adds a new attribute to object + """ + if not hasattr(obj, "__dict__"): + raise TypeError("can't add new attribute") + setattr(obj, name, value)