Q:

Program for students marks list using class in Python

belongs to collection: Python class & object programs

0

All the teachers of all the classes in the school requested the school's Principal to digitalize the student marks record system. Traditionally they are using pen paper for writing the marks of students and make a paper list, which is prone to get lost and there are chances of error also. Listening to the student's perspective the principal assigned its Computer Science Teacher to implement a program for making the list which contains roll numbername, and marks of the students.

The CS teacher decided to use Python - Class for data abstraction and implemented in the this way.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# Definig a class student, which contain 
# name and Roll number and marks of the student

class Student(object):
    def __init__(self, name, roll, marks):
        self.name = name
        self.roll = roll
        self.marks = marks
    
    def getmarks(self):
        return self.marks
    
    def getroll(self):
        return self.roll
    
    def __str__(self):
        return self.name + ' : ' + str(self.getroll()) +'  ::'+  str(self.getmarks())
  
# Defining a function for building a Record 
# which generates list of all the students    
def Markss(rec, name, roll, marks):
    rec.append(Student(name, roll, marks))
    return rec

# Main Code
Record = []
x = 'y'
while x == 'y':
    name = input('Enter the name of the student: ')
    height = input('Enter the roll number: ')
    roll = input('Marks: ')
    Record = Markss(Record, name, roll, height)
    x = input('another student? y/n: ')
    
# Printing the list of student
n = 1
for el in Record:
    print(n,'. ', el)
    n = n + 1

Output

Enter the name of the student: Prem
Enter the roll number: 101
Marks: 200
another student? y/n: y
Enter the name of the student: Shivang
Enter the roll number: 102
Marks: 250
another student? y/n: y
Enter the name of the student: Radib
Enter the roll number: 103
Marks: 230
another student? y/n: n
1 .  Prem : 200  ::101
2 .  Shivang : 250  ::102
3 .  Radib : 230  ::103

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python class & object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Program to manage a phone store (mobile shop) reco... >>
<< Building Restaurant Menu using Class in Python...