How to convert days into human-readable weeks and days in Python

2 Answers

0 votes
days = 26

weeks, remainder_days = divmod(days, 7)

str = f"{weeks} Weeks, {remainder_days} days"

print(str)



'''
run:

3 Weeks, 5 days

'''

 



answered Jun 26, 2024 by avibootz
0 votes
def to_readable_weeks_days(total_days: int) -> str:
    weeks = total_days // 7      # whole weeks
    days = total_days % 7        # leftover days

    return f"{weeks} week{'s' if weeks != 1 else ''} and {days} day{'s' if days != 1 else ''}"


def main():
    days = 26
    print(to_readable_weeks_days(days))


if __name__ == "__main__":
    main()




'''
run:

3 weeks and 5 days

'''

 



answered Dec 31, 2025 by avibootz

Related questions

...