Docsity

Python CS 1301 Object Oriented Programming Creating New Class for A New Class Member, Summaries of Computer Fundamentals

Toggle sidebar
bg1
Create new instance of class for a new class
member 5.1.2
1| class Student:
2| def __init__(self):
3| self.studentName = ""
4| self.GPA = 0.0
5| self.creditHours = 0
6| self.enrolled = True
7| self.classes = []
#Using the same Student class from before, let's imagine we want to create a
new student with the following values:
Student's Name: "George P. Burdell"
Enrolled: True
GPA: 3.9
Credit Hours: 1334
Classes: ["CS1301", "PHYS3001", "ISYE3029"]
#First, enter the line of code that will create a variable called newStudent
of type Student. Note that all parts of #this exercise are case-sensitive,
and you should avoid using duplicate spaces or switching between quotes and
#apostrophes for creating strings.
newStudent = Student()
#Next, enter the line of code that will set the value of enrolled for
newStudent to the boolean True:
newStudent.enrolled = True
#Next, enter the line of code that will set the value of GPA for newStudent
to the float 3.9:
newStudent.GPA = 3.9
#Next, enter the line of code that will set the value of creditHours for
newStudent to the integer 1334:
newStudent.creditHours = 1334
pf3
pf4

Partial preview of the text

Download Python CS 1301 Object Oriented Programming Creating New Class for A New Class Member and more Summaries Computer Fundamentals in PDF only on Docsity!

Create new instance of class for a new class

member 5.1.

1 | class Student: 2 | def init(self): 3 | self.studentName = "" 4 | self.GPA = 0. 5 | self.creditHours = 0 6 | self.enrolled = True 7 | self.classes = [] #Using the same Student class from before, let's imagine we want to create a new student with the following values:

Student's Name: "George P. Burdell" Enrolled: True GPA: 3. Credit Hours: 1334 Classes: ["CS1301", "PHYS3001", "ISYE3029"] #First, enter the line of code that will create a variable called newStudent of type Student. Note that all parts of #this exercise are case-sensitive, and you should avoid using duplicate spaces or switching between quotes and #apostrophes for creating strings.

newStudent = Student()

#Next, enter the line of code that will set the value of enrolled for newStudent to the boolean True:

newStudent.enrolled = True

#Next, enter the line of code that will set the value of GPA for newStudent to the float 3.9:

newStudent.GPA = 3.

#Next, enter the line of code that will set the value of creditHours for newStudent to the integer 1334:

newStudent.creditHours = 1334

#Next, enter the line of code that will set the value of classes for newStudent to the list ["CS1301", "PHYS3001", "ISYE3029"]:

newStudent.classes = ["CS1301", "PHYS3001", "ISYE3029"]

Number.py Submit Run Grades Reset

[Executed at: Tue Apr 7 18 : 11 :06 PDT 2026 ]

Well done! You can see the full results of your submission by selecting full_results.txt from the dropdown in the top left. You should see your score updated on your Progress page as well.

You might also find some sample_answer files in the drop down with other answers to this problem. If they are available, we recommend reading them to see some optimal approaches! value 1 #Write a class named "Number" with one attribute called 2 #"value" which defaults to 0 and another attribute called 3 #"even" which defaults to True. 4 # 5 #Next, create an instance of this class and assign it to 6 #a variable called "number_instance". 7 # 8 #Then, set the value attribute to 101 and the even 9 #attribute to False. 10