CBSE Class 11 Computer Science Question 33 of 63

Introduction to Python Modules — Question 2

Back to all questions
2
Question

Question 2

Write a module to input total number of days and find the total number of months and remaining days and display it in another program.

Answer
# days.py
def calculate(total_days):
    months = total_days // 30
    remaining_days = total_days % 30
    return months, remaining_days
# calculate.py
from days import calculate

total_days = int(input("Enter the total number of days: "))
months, remaining_days = calculate(total_days)
print("Total number of months:", months)
print("Remaining days:", remaining_days)
Output
Enter the total number of days: 100
Total number of months:  3
Remaining days:  10