当前位置:网站首页>Define a student class 1 to get the student's name: get_ Name() return type: STR 2 get student's age: get_ Age() return type: int 3 returns the highest score among the three subjects. get_ course()
Define a student class 1 to get the student's name: get_ Name() return type: STR 2 get student's age: get_ Age() return type: int 3 returns the highest score among the three subjects. get_ course()
2022-04-22 07:18:00 【Gratifying clover (●  ̄ (エ)  ̄ ●)】
One 、 Define a student Student class . There are the following class properties : 1 full name name 2 Age age 3 achievement score( Chinese language and literature , mathematics , English ) [ The type of grade in each class is integer ] Class method : 1 Get the student's name :get_name() Return type :str 2 Get student's age :get_age() Return type :int 3 return 3 The highest score in a subject .get_course() Return type :int After writing the class , Can define 2 Let's take a test : zm = Student(‘zhangming’,20,[69,88,100]) Return results : zhangming 20 100
Method 1 :
class Student():
def __init__(self, name, age, *score):
self.name = name
self.age = age
self.score = score
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_course(self):
return max(max(self.score))
zm = Student('zhangming', 20, [69, 88, 100])
Cyg = Student('CaoYougen', 21, [80, 100, 30])
print(' The student's name is : ',zm.get_name(), '\n',' The age of the students is :',zm.get_age(), '\n','3 The highest score in this subject is :',zm.get_course())
print()
print(' The student's name is : ',Cyg.get_name(), '\n',' The age of the students is :',Cyg.get_age(), '\n','3 The highest score in this subject is :',Cyg.get_course())
title 
Method 2 :
class Student:
name = ""
age = score_yu = score_shu = score_ying = 0
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_course(self):
return max(self.score_yu, self.score_ying, self.score_shu)
stu = Student()
stu.name = input(" Please enter the student's name :")
stu.age = input(" Please enter the age of the student :")
stu.score_yu = (int(input(" Please input Chinese score :")))
stu.score_shu = (int(input(" Please enter the math score :")))
stu.score_ying = (int(input(" Please enter your English score :")))
print(" The name is :", stu.get_name())
print(" Age is :", stu.get_age())
print(" The highest score is :", stu.get_course())

版权声明
本文为[Gratifying clover (●  ̄ (エ)  ̄ ●)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220609573164.html
边栏推荐
- ROS安装及基础与入门
- Quartus II防止信号被综合
- 软件工程导论第六版复习(笔记)
- 假设成年人的体重和身高存在此种关系: 身高(厘米)-100=标准体重(千克) 如果一个人的体重与其标准体重的差值在正负5%之间,显示“体重正常”,其他则显示“体重超标”。编写程序,能处理用户输入的
- ASP. Net daily development notes ---- record logs with text documents
- Distributed task scheduling and computing framework: powerjob quick start (local ide version) 02
- win10 anaconda安装cocotb
- Process of stepping on the pit in the flutter environment
- 桥接模式下主机ping不通虚拟机
- Clion and dynamic link library
猜你喜欢

Use of Tencent cloud object storage service

Does microelectronics major make chips? What is the chip related to?

Scope and lifetime (Mr. Weng Kai)

Pixhawk4+Up Board / NUC Implement VIO By Deploying T265

微信浏览器无法长期保存cookie

【JEECG】修改Viser图表颜色样式

short circuit

设计一个圆类(circle),内有私有成员radius代表半径, 函数get_radius( )用于获得半径、area( )用于计算圆的面积; (2)定义一个桌子类table,内有私有数据h

Powerjob workflow

完成一个学生信息管理系统,系统练习面向对象、函数、字符串等知识。实现知识的综合应用。 使用类、函数、数据库等来实现
随机推荐
Notes on daily development ---- some easy-to-use settings on vs
win10 anaconda安装cocotb
Leetcode punch in
Wechat browser cannot save cookies for a long time
Introduction to IC Analog Layout - learning notes on layout Basics (4)
. net learning notes - about Net core (1) [. NETCORE's project structure, five ways to transfer values to pages, and the use of log4net and NLog]
Build ES6 development environment and compile in real time
搭建ES6开发环境,实时编译
Use of Tencent cloud object storage service
ASP. Net daily development notes ----- send email
XPath of crawler notes
C语言 | 快速排序
paging
再见了Postman,有一说一:Apifox才是YYDS
C语言 | i++ 与 ++i
win10修改命令行默认字体
桥接模式下主机ping不通虚拟机
【JEECG】修改Viser图表颜色样式
Jenkins部署pm2
Beyond Compare“授权密钥已被吊销”的解决办法