This Python program receives a number representing years and calculates:
- The equivalent number of months
- The approximate number of days (using 365.25 days per year)
- The total number of seconds
It uses standard time conversion formulas:
days = years × 365.25
months = days ÷ 30
seconds = days × 24 × 60 × 60
# Get input from user
years = float(input("Enter number of years: "))
# Calculate time units
days = years * 365.25
months = days / 30
seconds = days * 24 * 60 * 60
# Display results
print("\n--- Result ---")
print(f"Months: {months:.2f}")
print(f"Days: {days:.2f}")
print(f"Seconds: {seconds:.0f}")
Enter number of years: 2
--- Result ---
Months: 24.35
Days: 730.50
Seconds: 63115200
- The program uses 365.25 to account for leap years
- Months are estimated by dividing days by 30
- Seconds are calculated by multiplying days by 24 hours × 60 minutes × 60 seconds
- Results are formatted for clarity and precision