这里-我修正了calculate_age(),你可以试试“计算年份”。在class AgeCalculator: #No arg needed to write this simple class
def calculate_age(): # Check your sample code, no 'self' arg needed
#age = input("What is your age?") #Can't use for testing
print ('What is your age?') #Can use for testing
age = '9' # Here is where I put in a test age, substitutes for User Imput
age = int(age)
print("Your age is:", age)
#return age Also this is not needed for this simple function
def calculate_year(age): # Again, no 'Self' arg needed - I cleaned up your top function, you try to fix this one using my example
current_year = time.strftime("%Y")
current_year = int(current_year)
calculated_date = (current_year - age) + 100
print("You will be 100 in", calculated_date)
return calculated_date
AgeCalculator.calculate_age()
从我在你的代码中看到的,你应该看看如何构建函数,并且请不要以冒犯的态度对待它。你也可以通过运行它来手动测试你的函数。就你的代码而言,它不会运行。在
祝你好运!在