1.let us create a python class called Star(). Write Star() such that an instance (s1) of a star is created with the call s1=Star(…) where the calling parameters of Star() define all the information of the star, including, at least, name, distance, surface temperature and radius. Look these up for your favorite star and run a main that proves it works.
2. Next, create a second class called Information(). It will have zero calling parameters and just one item to remember in the self list, and call that item self.Sourcelist = [] and by so doing set the default value of Sourcelist to an empty list.
3. Write one function for the Information class called loadstars(). Within loadstars() create at least four instances of the Star class. That is, feed in the information about four stars and append them to the source list.
4. Finally, create a Python dictionary of the star list and have loadstars() return that dictionary. The dictionary key that gives you the star you want from the list should be the name of the star. Creation of the dictionary should be done with a loop, so one can add stars easily in the future.
#source code:
class Star:
def __init__(self,name,s_temp,distance,radius):
self.name=name
self.temp=s_temp
self.distance=distance
self.radius=radius
def data(self):
return
[self.name,self.temp,self.distance,self.radius]
class Information:
Sourcelist=[]
lsit=[]
def __init__(self):
self.Sourcelist=[]
def loadstars(self):
s2=Star("star1",1700,32,1300)
s3=Star("star2",1800,31,1200)
s4=Star("star3",1400,54,1350)
s5=Star("star4",1350,32,1243)
self.Sourcelist.append(s2.data())
self.Sourcelist.append(s3.data())
self.Sourcelist.append(s4.data())
self.Sourcelist.append(s5.data())
dict={}
for i in
range(len(self.Sourcelist)):
sub_list=self.Sourcelist[i][1:4]
dict[self.Sourcelist[i][0]]=sub_list
return dict
def main():
name="chickle"
distance=12000
s_temp=35
radius=1500
s1=Star(name,distance,s_temp,radius)
i1=Information()
print(i1.loadstars())
if __name__=="__main__":
main()
#output:
#if you have any doubt comment below...
Get Answers For Free
Most questions answered within 1 hours.