is there any way to print each new student without copping and pasting the code like I have done below? Could it be possible to use a loop or something like that?
class Student:
def __init__(self, name, course, age):
self.name = name
self.course = course
self.age = age
def roomNumber(self):
if self.course == "Computing":
room = "S227"
elif self.course == "Art":
room = "Art Studio 1"
else:
room = "Main hall"
return (room)
def parientSign(self):
if self.age > 17:
print("Parent doesn't need to sign")
else:
print("Parent needs to sign")
return
newStudent = Student("Name One", "Computing", 18)
newStudent1 = Student("Bob Smart", "Art", 19)
newStudent2 = Student("Big Terry", "Computing", 16)
print("Student Name: ", newStudent.name)
print("Student Course: ",newStudent.course)
print("Your room number is: ", newStudent.roomNumber())
print("Your Age is: ",newStudent.age)
newStudent.parientSign()
print ("\n--------------\n")
print("Student Name: ", newStudent1.name)
print("Student Course: ",newStudent1.course)
print("Your room number is: ", newStudent1.roomNumber())
print("Your Age is: ",newStudent1.age)
newStudent1.parientSign()
print ("\n--------------\n")
print("Student Name: ", newStudent2.name)
print("Student Course: ",newStudent2.course)
print("Your room number is: ", newStudent2.roomNumber())
print("Your Age is: ",newStudent2.age)
newStudent2.parientSign()
print ("\n--------------\n")