"""author 夏伟鑫"""
import random
class Computer:
def __init__(self, mark, color, ram1):
self.mark = mark
self.color = color
self.ram = ram1
def playgames(self):
print('我使用电脑打游戏')
def writecode(self):
print('我用电脑写代码')
def watchtv(self):
print('我用电脑看视频')
com1 = Computer('华硕', 'black', 8)
print(com1.mark)
com1.color = 'write'
com1.mouse = 'G502'
com1.playgames()
com1.watchtv()
com1.writecode()
setattr(com1, 'mark', '外星人')
setattr(com1, 'color', 'blue')
setattr(com1, 'color')
delattr(com1, 'mouse')
class People:
def __init__(self, name, age, dog):
self.name = name
self.age = age
self.dog = dog
def rundog(self):
print(self.name + '正在溜' + self.dog)
class Dog:
def __init__(self, name, age, color):
self.name = name
self.age = age
self.color = color
def wang(self):
print('汪汪汪')
peo1 = People('小明', 18, '大黄')
peo1.rundog()
class Yuan:
def __init__(self, r, s):
self.r = r
self.s = s
def zhouchang(self):
l1 = 2 * self.r * 3.14
return l1
class Student:
def __init__(self, name, age, num):
self.name = name
self.age = age
self.num = num
self.here = random.randint(0, 1)
def show(self):
if self.here == 0:
temp = False
else:
temp = True
print(self.name + '到教室了嘛?:' + temp)
print(self.age)
print(self.num)
class Bani:
def __init__(self, snamelist: list, classname):
self.snamelist = snamelist
self.classname = classname
def addstu(self):
name = input('输入学生姓名')
age = int(input('输入学生年龄'))
num = input('输入学生学号')
stu1 = Student(name, age, num)
self.snamelist.append(stu1)
def delstu(self, name):
for item in self.snamelist:
if self.snamelist == name:
self.snamelist.remove(item)
else:
print('没有该学生')
def callname(self):
for _ in self.snamelist:
here = random.randint(2)
if here == 0:
temp = False
else:
temp = True
print(self.name + '到教室了嘛?:' + temp)
def avgstu(self):
sum = 0
for stu1 in self.snamelist:
sum += stu1.age
return sum/len(self.snamelist)