Student height record program for a school in Python

Python program to for student height record for a school using Class and Objects.
Submitted by Anuj Singh, on May 05, 2020

A team of 5 people is assigned with a task to record the heights of students in a school and they have decided to make a python program using class to record all the student's height.

In the below program, we try to use class in python to build a Student Height Record program for a school. The Record will contain the student’s name along with its height. This article aims to develop an understanding of the usage of class in the student height record system.

Program:

# definig a class student, 
# which contain name and height of the student

class Student(object):
    def __init__(self, name, height):
        self.name = name
        self.height = height
    
    def getheight(self):
        return self.height
    
    def __str__(self):
        return self.name + ' : ' + str(self.getheight())
  
# Defining a function for building a Menu 
# which generates list of Food    
def HeightRecord(rec, name, height):
    rec.append(Student(name, height))
    return rec

Record = []
x = 'y'
while x == 'y':
    name = input('Enter the name of the student: ')
    height = input('Enter the height recorded: ')
    Record = HeightRecord(Record, name, height)
    x = input('another student? y/n ')
    
n = 1
for el in Record:
    print(n,'. ', el)
    n = n + 1

Output

Enter the name of the student: Prerana Jain
Enter the height recorded: 165
another student? y/n y
Enter the name of the student: Monika Sharma
Enter the height recorded: 167
another student? y/n y
Enter the name of the student: Shivang Yadav
Enter the height recorded: 170
another student? y/n y
Enter the name of the student: Radib Kar
Enter the height recorded: 169
another student? y/n n
1 .  Prerana Jain : 165
2 .  Monika Sharma : 167
3 .  Shivang Yadav : 170
4 .  Radib Kar : 169

Python class & object programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.