SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
Programming
Exercise:
Programming Excercises
Question:7 | ISBN:978013274719 | Edition: 6

Question

(Find the number of years and days) Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days. Here is a sample run:

Enter the number of minutes: 1000000000
1000000000 minutes is approximately 1902 years and 214 days

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

The following program that prompts the user to enter the minutes (e.g., 1 billion), and displays the number of years and days for the minutes:

CODE WITH COMMENTS:

Minutes=int(input("Enter the number of minutes:")) #taking input number os minutes 
total_number_of_days = Minutes//(60*24)                 #dividing minutes with 24*60 gives number_of_days
number_of_years = total_number_of_days//365              # dividing number_of_days with 365 gives number_of_years
leftover_number_of_days = total_number_of_days % 365  #modulus of  total_number_of_days with 365 gives leftover_number_of_days
print(Minutes,"minutes is approximately",number_of_years,"years and",leftover_number_of_days,"days")  #diaplay final result

OUTPUT:

Enter the number of minutes:1000000000
1000000000 minutes is approximately 1902 years and 214 days


Enter the number of minutes:173942936
173942936 minutes is approximately 330 years and 343 days

 

0 0

Discussions

Post the discussion to improve the above solution.