Question: Need help fixing a Python program! The program description is below: Develop a Python program. Define a Cours e class with the following components (attributes):
Need help fixing a Python program! The program description is below:
Develop a Python program. Define a Course class with the following components (attributes):
- Course Name
- Course number
- Section
- Term and year
- Number of students
This class includes several methods: to change the values of these attributes, and to display their values. Separately, the main program must:
- Define an array of courses
- request the corresponding data from input and create a course object.
- invoke a method to change the value of one of its attributes of the object
- store the object in the array
- invoke a method that displays the value of each attribute of every course in the array.
Also include the source code, which must be well-structured, well commented, and clear to read and understand. Note: do not hard code any input data in the source code.
Here's my code so far:
# Define Course class class Course: name = '', class_num = 0, section = '', term = 0, year = 0, num_of_students = 0 # Init method - Constructor def __init__(self,name,number,section,term,year,num): self.name = name self.class_num = number self.section = section self.term = term self.year = year self.num_of_students = num # Method changes course name def change_name(self,name): self.name = name # Method prints course data def print_data(self): print(" Course name =",self.name," Course number =",self.class_num," Section =",self.section," Term =",self.term," Year =",self.year," Number of Students =",self.num_of_students) # Main method def main(): # Create an array of courses # Use append method to add course object into the list array_of_obj = [] # Create a Course object course_obj = Course(name,number,section,term,year,num) n = input(course_obj.name = input("Enter name of course: ") course_obj.class_num = input("Enter course number: ") course_obj.section = input("Enter course section: ") course_obj.term = input("Enter course term: ") course_obj.year = input("Enter course year: ") course_obj.num_of_students = ("Enter number of students present in course: "))) array_of_obj.append(n) # Call change name function to change the name of the course array_of_obj[1].change_name() # Iterate through each course object # Print each object called with print_data() for each in array_of_obj: each.print_data() if __name__== "__main__": main() Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
