28 lines
973 B
Python
28 lines
973 B
Python
import time
|
|
|
|
def get_birth_date():
|
|
"""Prompts the user for year, month, and day as integers."""
|
|
year = int(input("Enter birth year (e.g., 1997): "))
|
|
month = int(input("Enter birth month (1-12): "))
|
|
day = int(input("Enter birth day (1-31): "))
|
|
return year, month, day
|
|
|
|
def display_birth_info(year, month, day):
|
|
"""Converts the input integers to a time structure and displays formatted output."""
|
|
date_tuple = (year, month, day, 0, 0, 0, 0, 0, -1)
|
|
|
|
parsed_time = time.struct_time(date_tuple)
|
|
|
|
seconds = time.mktime(parsed_time)
|
|
formatted_struct = time.localtime(seconds)
|
|
|
|
# Format date string as DD/Mon/YY (e.g., 15/Jan/97)
|
|
formatted_date = time.strftime("%d/%b/%y", formatted_struct)
|
|
|
|
day_of_week = time.strftime("%A", formatted_struct)
|
|
|
|
print(f"\nDate entered: {formatted_date}")
|
|
print(f"You were born on a {day_of_week}.")
|
|
|
|
year, month, day = get_birth_date()
|
|
display_birth_info(year, month, day) |