Tell us what’s happening:
i’m getting the desired output bit sm getting the following error messages:
4. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the first argument passed in is not a string type.
5. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the second argument passed in is not a string type.
6. The __init__ method should raise a TypeError with the message name, planet type, and star must be strings if the third argument passed in is not a string type.
7. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the first argument passed in is an empty string.
8. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the second argument passed in is an empty string.
9. The __init__ method should raise a ValueError with the message name, planet_type, and star must be non-empty strings if the third argument passed in is an empty string.
14. The orbit method should return a string in the format {name} is orbiting around {star}....
// tests completed
// console output
Planet: Mercury | Type: Ice | Star: Sun
Planet: Saturn | Type: Giant | Star: Sun
Planet: Jupiter | Type: Giant | Star: Sun
Mercury is orbiting around Sun
Saturn is orbiting around Sun
Jupiter is orbiting around Sun
I don’t know what i’m doing wrong. here’s my code:
Your code so far
class Planet:
def __init__(self,name,planet_type,star):
if name == "":
raise TypeError(f'name, planet type, and star must be strings')
if planet_type == '':
raise TypeError(f'name, planet type, and star must be strings')
if star == "":
raise TypeError(f'name, planet type, and star must be strings')
if not isinstance(name,str):
raise ValueError(f'name, planet_type, and star must be non-empty string')
if not isinstance(name,str):
raise ValueError(f'name, planet_type, and star must be non-empty string')
if not isinstance(name,str):
raise ValueError(f'name, planet_type, and star must be non-empty string')
self.name = name
self.planet_type = planet_type
self.star = star
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("Mercury","Ice","Sun")
planet_2 = Planet("Saturn","Giant","Sun")
planet_3 = Planet("Jupiter","Giant","Sun")
print(planet_1)
print(planet_2)
print(planet_3)
print("\n")
print(planet_1.orbit())
print(planet_2.orbit())
print(planet_3.orbit())
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15
Challenge Information:
Build a Planet Class - Build a Planet Class