现在正在做作业。任务是为学生创建课程。但是由于某种原因,我无法计算出那里的年龄?
尝试了几种方法,但对我没有任何帮助。不断收到此错误“ TypeError:'tuple'对象不可调用”
from datetime import datetime
def get_date_today():
return (2013, 10, 30)
dt = datetime(*get_date_today())
class Student:
def __init__(self, name, surname, birthdate, branch, grades):
self.name = name
self.surname = surname
self.birthdate = birthdate
self.branch = branch
self.grades = grades
def age(self):
return (datetime(*get_date_today()) - datetime(*self.birthdate())).days/365
def print_details(self):
print("Name:", self.name)
print("Grades:", self.grades)
print('Age: ', self.age())
print('Branch: ', self.branch)
print('Grades:', self.grades)
Will = Student('Will', 'Smith', (2001,10,12), 'Philosophy', [12,11,10,10,9,8])
print(Will.print_details())
答案 0 :(得分:1)
将datetime(*self.birthdate())
更改为
datetime(*self.birthdate)
属性self.birthdate
是一个元组/列表,而不是一个函数。