class UniversityAthletics():
def __init__(self, university_name, sport):
self.name = university_name
self.sport = sport
self.tickets_sold = 10
def tickets_sold(self):
"""This just tells you how many tickets have been sold"""
print(str(self.tickets_sold) + " tickets have been sold")
def describe_athletics(self):
print(self.name.title() + " " + self.sport.title())
def in_season(self):
print(self.sport.title() + " is in season.")
def set_tickets_sold(self, numticket):
"""This sets the number of tickets that have been sold"""
self.tickets_sold = numticket
def increment_tickets_sold(self, moretickets):
"""This increments the number of tickets sold"""
self.tickets_sold += moretickets
athletics = UniversityAthletics('salisbury university', 'soccer')
athletics.set_tickets_sold(20)
athletics.tickets_sold()
athletics.increment_tickets_sold(500)
athletics.tickets_sold()
我试图设置一个属性,设置售出的票数'set_tickets_sold',然后是一个属性,用于更改票证'increment_tickets_sold'的数量,但是当我尝试设置票数时,然后调用方法'tickets_sold ()'我一直收到错误。
Traceback(最近一次调用最后一次):文件 “E:/ WorWic / IntroToProgramming / chapter9 /大学田径部分 2.py“,第29行,in athletics.tickets_sold()TypeError:'int'对象不可调用
我做错了什么?
答案 0 :(得分:1)
您的问题是tickets_sold
既是属性又是函数名称。它获取属性并调用它,而不是函数。我建议将你的功能重命名为其他内容。