Build a Planet Class - Build a Planet Class

Tell us what’s happening:

what exactly is the problem here? im failing every test and i dont get why, i suspect its because of the for loop i use to check if the attributes are valid but im not sure, any help?

Your code so far

class Planet:
    def __init__(self, name, planet_type, star):
        self.name = name
        self.planet_type = planet_type
        self.star = star
        attributes_to_check = (name, planet_type, star)
        for attribute in attributes_to_check:
            if attribute is not isinstance(attribute, str):
                raise TypeError("name, planet type, and star must be strings")
                return
            elif attribute == False:
                raise ValueError("name, planet_type, and star must be non-empty strings")
                return
    
    def orbit(self):
        return f"{self.name} is orbiting around {self.star}..."
    
    def __str__(self):
        return f"Planet: {self.name} | Type: {self.planet_type} | Star: {self.star}"

planet_1 = Planet("Earth", "Terran", "Sol")
planet_2 = Planet("Mars", "Barren", "Sol")
planet_3 = Planet("Kepler-1b", "Barren", "Proxima_Centauri")


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0

Challenge Information:

Build a Planet Class - Build a Planet Class

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-planet-class/68e76b1ce8216249d04df670.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @harrybrownsmith656,

There is an error in the console:

Traceback (most recent call last):
  File "main.py", line 21, in <module>
  File "main.py", line 9, in __init__
TypeError: name, planet type, and star must be strings

Does it make sense to assign attribute values before you validate them?

Please check your syntax here.

Happy coding

thank you very much, i fixed it, as of now im finishing up the problem