Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Printing Name Errors

class User:
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name.upper()


class UserProfile:
    def __init__(self, user):
        self.user = user

    def print_profile(self):
        print(f"Name: {self.user.get_name()}")

profile = UserProfile()

profile.print_profile()

what am i not getting here?

I tried to get some profile name inserted through input it was causing error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

class User:
    def __init__(self, name):
        self.name = name

    def get_name(self):
        return self.name.upper()


class UserProfile:
    def __init__(self, user):
        self.user = user

    def print_profile(self):
        if self.user:
            print(f"Name: {self.user.get_name()}")
        else:
            print("No user profile available")

# Creating a User instance and passing it to UserProfile
user = User("AAAAA")
profile = UserProfile(user)

# Printing profile only if user is initialized
profile.print_profile()

Try this . Thank you
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading