Q:

Student height record program for a school in Python

belongs to collection: Python class & object programs

0

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.

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 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

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
Building Restaurant Menu using Class in Python... >>
<< Python program to check Palindrome number using ob...