52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
# def fac(x,y=2):
|
|
# return x**y
|
|
# list = [1,2,3]
|
|
# list2 =[]
|
|
# for i in range(len(list)):
|
|
# list[i] = fac(list[i])
|
|
# print (list)
|
|
|
|
|
|
class Lecture:
|
|
def __init__(self, title):
|
|
"""
|
|
Initializes a new Lecture instance with a title and an empty list of students.
|
|
|
|
:param title: Title of the lecture
|
|
"""
|
|
self.title = title
|
|
self.students = []
|
|
|
|
def add_student(self, student_name):
|
|
"""
|
|
Adds a student to the lecture.
|
|
|
|
:param student_name: Name of the student to be added
|
|
"""
|
|
if student_name not in self.students:
|
|
self.students.append(student_name)
|
|
print(f"{student_name} has been added to the lecture '{self.title}'.")
|
|
else:
|
|
print(f"{student_name} is already enrolled in the lecture '{self.title}'.")
|
|
|
|
def number_of_students(self):
|
|
"""
|
|
Returns the number of students enrolled in the lecture.
|
|
|
|
:return: The count of students
|
|
"""
|
|
return len(self.students)
|
|
|
|
|
|
# Example usage
|
|
|
|
# Create a new lecture
|
|
python_lecture = Lecture("Introduction to Python")
|
|
# Add students
|
|
python_lecture.add_student("Alice")
|
|
python_lecture.add_student("Bob")
|
|
python_lecture.add_student("Alice") # Attempt to add Alice again
|
|
|
|
# Get the number of students
|
|
print(f"Number of students enrolled in '{python_lecture.title}': {python_lecture.number_of_students()}")
|