python 程序耗时记录_Python学校的学生身高记录程序

python 程序耗时记录

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.

由5人组成的小组负责记录学校中学生的身高,他们决定使用课堂制作python程序来记录所有学生的身高。

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.

在下面的程序中,我们尝试使用python中的class来为学校构建Student Height Record程序 。 记录将包含学生的姓名及其身高。 本文旨在加深对学生身高记录系统中班级用法的理解。

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


翻译自: https://www.includehelp.com/python/student-height-record-program-for-a-school.aspx

python 程序耗时记录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值