-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ11.py
More file actions
30 lines (21 loc) · 710 Bytes
/
Q11.py
File metadata and controls
30 lines (21 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Create a class called Classroom with:
#A list called students
#A method add_student(name) to add a name to the list
#A method print_students() to print all student names
#Create an object and add at least 3 students.
class Classroom:
def __init__(self):
self.students = []
def add_student(self, name):
self.students.append (name)
def print_students(self):
print("Student List:")
for student in self.students:
print(f" {student}")
my_classroom = Classroom()
# Add at least 3 students
my_classroom.add_student("prachi")
my_classroom.add_student("abc")
my_classroom.add_student("xyz")
my_classroom.print_students()
my_classroom.add_student("xyz")