定义个Student类: 属性:身份证号码、姓名、性别、年龄、籍贯、住址,学号; 方法:eat,sleep,print,study;
时间: 2023-12-22 19:23:42 浏览: 137
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
class Student:
def __init__(self, id_number, name, gender, age, hometown, address, student_id):
self.id_number = id_number
self.name = name
self.gender = gender
self.age = age
self.hometown = hometown
self.address = address
self.student_id = student_id
def eat(self):
print("{} is eating".format(self.name))
def sleep(self):
print("{} is sleeping".format(self.name))
def print_info(self):
print("Name: {}".format(self.name))
print("ID Number: {}".format(self.id_number))
print("Gender: {}".format(self.gender))
print("Age: {}".format(self.age))
print("Hometown: {}".format(self.hometown))
print("Address: {}".format(self.address))
print("Student ID: {}".format(self.student_id))
def study(self):
print("{} is studying".format(self.name))
阅读全文