18
while True:
try:
n=int(input('请输入评委人数:'))
if n <=2:
print('评委人数太少,必须多于2个人。')
else:
break
except:
pass
scores=[]
for i in range(n):
#这个while循环用来保证用户必须输入0~100之间的数字
while True:
try:
score=input('请输入第{0}个评委的分数:'.format(i+1))
#把字符串转换为实数
score=float(score)
assert 0<=score<=100
scores.append(score)
#如果数据合法,跳出while循环,继续输入下一个评委的分数
break
except:
print('分数错误')
#计算并删除最高分与最低分
highest=max(scores)
lowest=min(scores)
scores.remove(highest)
scores.remove(lowest)
finalScore=round(sum(scores)/len(scores),2)
formatter='去掉一个最高分{0}\n去掉一个最低分{1}\n最后得分{2}'
print(formatter.format(highest,lowest,finalScore))
19A
class Car:
def __init__(self,name):
self.innername=name
print(self.innername,"Car is produced.")
def Run(self):
print(self.innername,"Car is running...")
BenzCar=Car("Benz")
BenzCar.Run()
VolkswagenCar=Car("Volkswagen")
VolkswagenCar.Run()
19B:
class Student:
def __init__(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex
print("{0} is a Htzd student.".format(self.name))
def WhatIsYourName(self):
print("My Name is {0} ".format(self.name))
def HowOldAreYou(self):
if(self.sex=='f' and self.age>=30):
print("I am {0} years old".format(self.age-5))
else:
print("I am {0} years old".format(self.age))
obj1=Student("张三",16,'m')
obj2=Student("王莎莎",30,'f')
obj1.WhatIsYourName()
obj2.HowOldAreYou()
20:
class Student:
SchoolName="Xi\'an AeroSpace Technical College"
def __init__(self,name,age,gender):
self.__name=name
self.__age=age
self.gender=gender
print("{0} is a student".format(self.__name))
def __del__(self):
print("{0} is not a student".format(self.__name))
def YourName(self):
print("My Name is {0}".format(self.__name))
def YourAge(self):
if self.gender=='f' and self.__age>=30:
print("I am {0} years old".format(self.__age-5))
else:
print("I am {0} years old".format(self.__age))
def YourSchoolName(self):
print("My School Name is {0}".format(self.SchoolName))
obj1=Student("张三",16,'m')
obj2=Student("李四",17,'m')
obj1.YourAge()
obj3=Student("王莎莎",31,'f')
obj3.YourAge()
#print(obj3.__age)
print("----------------------")
del obj2
obj1.YourSchoolName()
print("SchoolName:",Student.SchoolName)
print("----------------------")