Question

1. let us create a python class called Star(). Write Star() such that an instance (s1)...

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.

5.

The main should look something like:

#Main Starts Here

Inf=Information()

StarDict = Inf.loadstars()

print(StarDict['Tau Ceti'].distance)

print(“End of Run”)

Here is the datatable:

4.20985 17.1047
4.82755 16.4046
3.17238 12.1246
4.50796 18.0955
6.04241 21.1016

Thank you so much, it is in python 3.7.

no output examples, sorry...

Homework Answers

Answer #1

Solution :-

#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()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.let us create a python class called Star(). Write Star() such that an instance (s1) of...
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...
On python a) Create a dictionary with 5 to 10 key-values so that state is the...
On python a) Create a dictionary with 5 to 10 key-values so that state is the key and its capital is the value. Print the dictionary and its length. b) Create and print a list of states and a list of capitals. c) Ask the user for a state's name. Check to see if the state's name exists in the list of states. If it does, look up the state's name in the dictionary and print out its capital. If...
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called...
Assignment 1. Console Application IN PYTHON For this assignment you are to create a class called Lab1. Inside the class you will create three methods that will modify a three-digit whole number: sumNums - This method takes as input a three digit int and returns the sum of the three numbers. For instance, 123 would return 6 because 3 + 2 + 1 is 6 reverseNums - This method takes as input a three digit whole number and returns the...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145' PYTHON
write code using python or repl.it 1. List 4 attributes that you'd create for class "student"....
write code using python or repl.it 1. List 4 attributes that you'd create for class "student". 2. List 2 setters and 2 getters for class student including their parameters 3. Write the complete definition for class student including attributes and methods created above using the correct Python syntax. 4. Create one object of class student and print the values of all its attributes. You can either call the getter method or access the attribute directly using the dot notation.
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
By using Python: a, Make a class called Book. The __init__() method for Book should store...
By using Python: a, Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library. b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods.
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
Python 3 We’re going to create a class which stores information about product ratings on a...
Python 3 We’re going to create a class which stores information about product ratings on a website such as Amazon. The ratings are all numbers between 1 and 5 and represent a number of “stars” that the customer gives to the product. We will store this information as a list of integers which is maintained inside the class StarRatings. You will be asked to write the following: 1) A constructor which takes and stores the product name. 2) A function...
For this assignment, you'll create a Player class that captures information about players on a sports...
For this assignment, you'll create a Player class that captures information about players on a sports team. We'll keep it generic for this assignment, but taking what you learn with this assignment, you could create a class tailored to your favorite sport. Then, imagine using such a class to track the stats during a game. Player Class Requirements Your class should bet set up as follows: Named Player Is public to allow access from other object and assemblies Has a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT