Skip to content

Age_Calculator: months/days math produces impossible values (e.g. 18 months) #3322

Description

@chirag127

Problem

Age_Calculator/Age_Calculator.py computes remaining_months and remaining_days with formulas that produce values >= 12 months and ignore month-length, giving nonsensical output.

Steps

cd Age_Calculator
python3 Age_Calculator.py
# Enter: 2000, 1, 15

Expected

Age: 26 years, 5 months, 19 days

Actual

Age: 26 years, 18 months, and 11 days

Bug at Age_Calculator/Age_Calculator.py:13-14:

remaining_months = abs((12-birthday.month)+today.month)
remaining_days = abs(today.day - birthday.day)

Formula adds instead of taking the wraparound modulo 12, and abs() on day-diff hides negative rollover instead of borrowing from months.

Environment

  • OS: Ubuntu 22.04
  • Python: 3.10.12
  • Repo commit: main @ 2026-07-04

Thanks for maintaining avinashkranjan/Amazing-Python-Scripts!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions