我是 Python OOP 的新手。请不要苛刻。这是我的代码,它从列表中计算出运动员的最快时间并显示出来。但是在运行时,我收到此错误:
z= add.mylist.min()
NameError: global name 'add' is not defined
我的代码:
class Athlete:
def add(self):
list=[]
mylist=[]
for i in range(2):
self.name = raw_input("Enter name: ")
self.fastest_time = input("time: ")
list.append(self.name)
mylist.append(self.fastest_time)
print "Names: ",list
print "Fastest times: ",mylist
def display(self):
z= add.mylist.min()
w= add.mylist.index(z)
print "Minimum time: ",z
print "Name of athelte with fastest time: ",list[w]
x = Athlete()
x.add()
x.display()