|
| 1 | +# This is simplest Student data management program in python |
| 2 | +# Create class "Student" |
| 3 | +class Student: |
| 4 | + # Constructor |
| 5 | + def __init__(self, name, rollno, m1, m2): |
| 6 | + self.name = name |
| 7 | + self.rollno = rollno |
| 8 | + self.m1 = m1 |
| 9 | + self.m2 = m2 |
| 10 | + |
| 11 | + # Function to create and append new student |
| 12 | + def accept(self, Name, Rollno, marks1, marks2 ): |
| 13 | + # use ' int(input()) ' method to take input from user |
| 14 | + ob = Student(Name, Rollno, marks1, marks2 ) |
| 15 | + ls.append(ob) |
| 16 | + |
| 17 | + # Function to display student details |
| 18 | + def display(self, ob): |
| 19 | + print("Name : ", ob.name) |
| 20 | + print("RollNo : ", ob.rollno) |
| 21 | + print("Marks1 : ", ob.m1) |
| 22 | + print("Marks2 : ", ob.m2) |
| 23 | + print("\n") |
| 24 | + |
| 25 | + # Search Function |
| 26 | + def search(self, rn): |
| 27 | + for i in range(ls.__len__()): |
| 28 | + if(ls[i].rollno == rn): |
| 29 | + return i |
| 30 | + |
| 31 | + # Delete Function |
| 32 | + def delete(self, rn): |
| 33 | + i = obj.search(rn) |
| 34 | + del ls[i] |
| 35 | + |
| 36 | + # Update Function |
| 37 | + def update(self, rn, No): |
| 38 | + i = obj.search(rn) |
| 39 | + roll = No |
| 40 | + ls[i].rollno = roll; |
| 41 | + |
| 42 | +# Create a list to add Students |
| 43 | +ls =[] |
| 44 | +# an object of Student class |
| 45 | +obj = Student('', 0, 0, 0) |
| 46 | + |
| 47 | +print("\nOperations used, ") |
| 48 | +print("\n1.Accept Student details\n2.Display Student Details\n" / |
| 49 | + / "3.Search Details of a Student\n4.Delete Details of Student" / |
| 50 | + / "\n5.Update Student Details\n6.Exit") |
| 51 | + |
| 52 | +# ch = int(input("Enter choice:")) |
| 53 | +# if(ch == 1): |
| 54 | +obj.accept("A", 1, 100, 100) |
| 55 | +obj.accept("B", 2, 90, 90) |
| 56 | +obj.accept("C", 3, 80, 80) |
| 57 | + |
| 58 | +# elif(ch == 2): |
| 59 | +print("\n") |
| 60 | +print("\nList of Students\n") |
| 61 | +for i in range(ls.__len__()): |
| 62 | + obj.display(ls[i]) |
| 63 | + |
| 64 | +# elif(ch == 3): |
| 65 | +print("\n Student Found, ") |
| 66 | +s = obj.search(2) |
| 67 | +obj.display(ls[s]) |
| 68 | + |
| 69 | +# elif(ch == 4): |
| 70 | +obj.delete(2) |
| 71 | +print(ls.__len__()) |
| 72 | +print("List after deletion") |
| 73 | +for i in range(ls.__len__()): |
| 74 | + obj.display(ls[i]) |
| 75 | + |
| 76 | +# elif(ch == 5): |
| 77 | +obj.update(3, 2) |
| 78 | +print(ls.__len__()) |
| 79 | +print("List after updation") |
| 80 | +for i in range(ls.__len__()): |
| 81 | + obj.display(ls[i]) |
| 82 | + |
| 83 | +# else: |
| 84 | +print("Thank You !") |
0 commit comments