Computer Science
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.
Python Modules
1 Like
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
Answered By
1 Like
Related Questions
Assertion (A): The output of print(math.factorial(4.5)) shall generate an error.
Reasoning (R): This factorial() function belongs to the statistics module in Python.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What is a Python library? Explain with examples.
What is a module? What is the file extension of a Python module?
How do you reuse the functions defined in a module in your program?