Tell us what’s happening:
My code is failing the error message steps 4-9. When empty strings or non-string integers and floats are inputted the correct error message is raised. What am I missing?
Your code so far
class Planet:
def __init__(self, name, planet_type, star):
self.name = name
self.planet_type = planet_type
self.star = star
for attr in (name, planet_type, star):
if not isinstance(attr, str):
raise TypeError('name, planet type and star must be strings')
if attr == '':
raise ValueError('name, planet type and star must be non-empty strings')
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', 'Rock', 'Sol')
planet_2 = Planet('Mars', 'Rock', 'Sol')
planet_3 = Planet('Neptune', 'Gas Giant', 'Sol')
print((planet_1))
print((planet_2))
print((planet_3))
print(planet_1.orbit())
print(planet_2.orbit())
print(planet_3.orbit())
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
Challenge Information:
Build a Planet Class - Build a Planet Class