i need a python code for calculating the age
- User
i need a python code for calculating the age
Assistant
pythondef calculate_age(birth_date): # Get the current date today = date.today() # Calculate the age in years age = today.year - birth_date.year # Return the age return age # Get the user's birth date birth_date = input("Enter your birth date (YYYY-MM-DD): ") # Calculate the age age = calculate_age(birth_date) # Print the age print(f"You are {age} years old.")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.