某大学举行新生歌唱大赛,要求从音乐素养,综合印象,歌曲诠释三项打分。具体定义一个新生歌手类Singer。有下面的类属性: 姓名、年龄、音乐素养,综合印象,歌曲诠释(打分项均为整数),且有以下的类方法: 获取学生的姓名:get_name() ;获取学生的年龄:get_age() ;返回三项中最高的分数和总分:get_item( ) 。 实例: zm = Singer('zhangming',18,80,90,85) 输出结果 : 姓名:zhangming 年龄:18 最高分:90 总分:255
时间: 2024-02-13 10:06:03 浏览: 16
好的,根据您的要求,我来为您编写一个 Singer 类:
```python
class Singer:
def __init__(self, name, age, music, impression, interpretation):
self.name = name
self.age = age
self.music = music
self.impression = impression
self.interpretation = interpretation
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_item(self):
items = [self.music, self.impression, self.interpretation]
highest = max(items)
total = sum(items)
return highest, total
```
然后,我们可以根据您提供的例子来创建一个 Singer 实例,并输出结果:
```python
zm = Singer('zhangming', 18, 80, 90, 85)
print('姓名:{}'.format(zm.get_name()))
print('年龄:{}'.format(zm.get_age()))
highest, total = zm.get_item()
print('最高分:{}'.format(highest))
print('总分:{}'.format(total))
```
输出结果:
```
姓名:zhangming
年龄:18
最高分:90
总分:255
```
相关推荐
![.rar](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)