python 我的年龄计算器有问题
i have a problem with my age calculator in python
我想要代码以这种格式打印人的年龄和出生日期(你 31 岁,你是星期五出生的)
但我在代码中遇到问题说(参数'fmt'未填充:11)
代码:
import datetime
def ma(birthdate):
today = datetime.date.today()
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)), birthdate.strftime('%A')
return age
print('You are', ma(datetime.date(int(input('Please Enter a Year: ')), int(input('Please Enter a Month: ')),
int(input('Please Enter a Day: ')))), 'years old, and you have born in', datetime.date.strftime('%A'))```
输出:
Please Enter a Year: 2007
Please Enter a Month: 8
Please Enter a Day: 17
Traceback (most recent call last):
File "C:\Users\walee\AppData\Roaming\JetBrains\PyCharmCE2021.3\scratches\age calculate.py", line 11, in <module>
int(input('Please Enter a Day: ')))), 'years old, and you have born in', datetime.date.strftime('%A'))
TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'str' object
Process finished with exit code 1```
简单胜于复杂。 (Python的禅)
age = ma(datetime.date(int(input('Please Enter a Year: ')),
int(input('Please Enter a Month: ')),
int(input('Please Enter a Day: '))))
print(f'You are {age[0]} years old and you were born on {age[1]}')
输出:
Please Enter a Year: 2007
Please Enter a Month: 8
Please Enter a Day: 17
You are 14 years old and you were born on Friday
我想要代码以这种格式打印人的年龄和出生日期(你 31 岁,你是星期五出生的) 但我在代码中遇到问题说(参数'fmt'未填充:11)
代码:
import datetime
def ma(birthdate):
today = datetime.date.today()
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)), birthdate.strftime('%A')
return age
print('You are', ma(datetime.date(int(input('Please Enter a Year: ')), int(input('Please Enter a Month: ')),
int(input('Please Enter a Day: ')))), 'years old, and you have born in', datetime.date.strftime('%A'))```
输出:
Please Enter a Year: 2007
Please Enter a Month: 8
Please Enter a Day: 17
Traceback (most recent call last):
File "C:\Users\walee\AppData\Roaming\JetBrains\PyCharmCE2021.3\scratches\age calculate.py", line 11, in <module>
int(input('Please Enter a Day: ')))), 'years old, and you have born in', datetime.date.strftime('%A'))
TypeError: descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'str' object
Process finished with exit code 1```
简单胜于复杂。 (Python的禅)
age = ma(datetime.date(int(input('Please Enter a Year: ')),
int(input('Please Enter a Month: ')),
int(input('Please Enter a Day: '))))
print(f'You are {age[0]} years old and you were born on {age[1]}')
输出:
Please Enter a Year: 2007
Please Enter a Month: 8
Please Enter a Day: 17
You are 14 years old and you were born on Friday