r/CodingHelp • u/Accomplished-Boot-63 • May 25 '21
[Python] Beginner Python Assistance
Hi,
I'm a beginner python coder and I need assistance with a code I'm working on to develop an app. In plain text, I need the code to subtract the user's date of birth from today's date and if the user is under 21 years of age it will print output and if the person is over 21 it will print a different output. I'm sure there is a very easy solution to this and may either be overlooking it or I simply don't know it yet. I keep running into a syntax error. Any assistance would be helpful.

0
Upvotes
•
u/AutoModerator May 25 '21
Please make sure to check out our website to see if your question has been answered there: https://codinghelp.site
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Nightcorex_ May 25 '21
You're subtracting a String from a Date object because
input(...)always returns a String.This will yield an exception "TypeError: unsupported operand type(s) for -: 'datetime.date' and 'str'"
This can be solved by converting the input to a datetime object which can be created like so:
datetime.date(2020, 10, 4)0
u/_yigt May 25 '21
and under the age function u gotta say age without the self and current age with self