|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
函数如下
n=int(input())
a = []
b = []
for i in range(n):
a.append('student_'+str(i))
class student:
def _init_(self,num,xueye,sutuo):
self.num = num
self.xueye = xueye
self.sutuo = sutuo
@property
def pingjia(self):
biaoxian = self.xueye*0.7+self.sutuo*0.3
zongfen = self.xueye+self.sutuo
if biaoxian>=80 and zongfen>140:
return 'Excellent'
else:
return 'Not excellent'
for i in range(n):
a[i] = input().split()
num_1 = int(a[i][0])
xueye_1 = int(a[i][1])
sutuo_1 = int(a[i][2])
b.append(student(num_1,xueye_1,sutuo_1))
for i in b:
i.pingjia()
简述就是定义一个学生类,有学号,学业成绩,素拓成绩,然后根据成绩评价该学生是否优秀,然后我这样写报错
b.append(student(num_1,xueye_1,sutuo_1))
TypeError: student() takes no arguments
我查了一下,如果修饰的话调用的时候不加括号
- n=int(input())
- a = []
- b = []
- for i in range(n):
- a.append(f'student_{i}')
- class student:
- def __init__(self,num,xueye,sutuo):
- self.num = num
- self.xueye = xueye
- self.sutuo = sutuo
- @property
- def pingjia(self):
- biaoxian = self.xueye*0.7+self.sutuo*0.3
- zongfen = self.xueye+self.sutuo
- if biaoxian>=80 and zongfen>140:
- return 'Excellent'
- else:
- return 'Not excellent'
- for i in range(n):
- a[i] = input().split()
- num_1 = int(a[i][0])
- xueye_1 = int(a[i][1])
- sutuo_1 = int(a[i][2])
- b.append(student(num_1,xueye_1,sutuo_1))
- for i in b:
- print(i.pingjia)
复制代码
https://zhuanlan.zhihu.com/p/64487092
|
|