Reputation: 21
I am trying to make small program where I can find the birth year, given the age,
import datetime
x=raw_input("your age is?")
y=datetime.datetime.now().strftime("%Y")
print y-x
However, this is not working because of the format of the output.
Upvotes: 0
Views: 473
Reputation: 5597
Your input and current year need to be integers.
from datetime import datetime
x = int(raw_input("What is your age? ")) # Get user's age
y = datetime.now().year # Get current year
print("Your birth year: {}".format(y-x)) # Print difference
Upvotes: 0
Reputation: 5664
The most straightforward way to get this should be
y = datetime.datetime.now().year
Upvotes: 2
Reputation: 44444
strftime(..)
returns a string. You need to convert into an int
.
y = int(datetime.datetime.now().strftime("%Y"))
Upvotes: 0