Question

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 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.

Homework Answers

Answer #1

#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...

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)...
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...
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.
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...
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)....
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...
Create a class called Employee that should include four pieces of information as instance variables—a firstName...
Create a class called Employee that should include four pieces of information as instance variables—a firstName (type String), a lastName (type String), a mobileNumber (type String) and a salary (type int). Your class (Employee) should have a full argument constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. The validation for each attribute should be like below: mobileNumber should be started from “05” and the length will be limited to 10...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
Using Java Write a class called Dog that contains instance data that represents the dog’s name,...
Using Java Write a class called Dog that contains instance data that represents the dog’s name, breed, weight, birth date, and medical history. Define the Dog constructor to accept and initialize instance data (begin the medical history with an empty line). Include accessor and mutator methods every attribute. For the medical history in particular, define the mutator method to simply add strings to the medical history so the user sees a printout of information about the dog (be mindful of...
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...