Which of the following would properly create a new student?

class Student:
def __init__(self, name, gpa, grade):
self.name = name
self.gpa = gpa
self.grade = grade
(1 point)
Responses

s1 = Student( “Jorge”, 12)
s1 = Student( “Jorge”, 12)

s1 = Student(“Jorge”, 3.4, 12)
s1 = Student(“Jorge”, 3.4, 12)

s1 = Student(self,“Jorge”, 3.4, 12)
s1 = Student(self,“Jorge”, 3.4, 12)

s1 = Student(3.4, “Jorge”, 12)

1 answer

To properly create a new Student object using the Student class defined with an __init__ method that requires three parameters (name, gpa, and grade), you need to pass values for all three of those parameters in the correct order.

Here are the responses you provided:

  1. s1 = Student( “Jorge”, 12)
    This is incorrect because it is missing the gpa parameter.

  2. s1 = Student( “Jorge”, 12)
    This is also incorrect for the same reason as the first response (missing the gpa).

  3. s1 = Student(“Jorge”, 3.4, 12)
    This is correct as it provides values for name, gpa, and grade.

  4. s1 = Student(“Jorge”, 3.4, 12)
    This is a repeat of the previous correct response.

  5. s1 = Student(self,“Jorge”, 3.4, 12)
    This is incorrect because self is not needed here; self is used within class methods to refer to the instance itself.

  6. s1 = Student(3.4, “Jorge”, 12)
    This is incorrect because it provides the arguments in the wrong order (the order should be name, gpa, grade).

Therefore, the correct options that properly create a new student are:

  • s1 = Student(“Jorge”, 3.4, 12)
  • s1 = Student(“Jorge”, 3.4, 12) (the same option repeated).