74.2k views
4 votes
Write a program that estimates the approximate number of times the user’s heart has beat in his/her lifetime using an average heart rate of 72 beats per minute and estimates the number of times the person has yawned in his/her lifetime using an average of 5 yawns per day. The program should have two functions, heartbeats(age) and yawns(age), that take age in years as an input parameter and returns the estimated number of heartbeats and the number of yawns, respectively. In your computation ignore the leap years.

1 Answer

4 votes

Answer:

The code snippet given in python for resolve this question is the following:

import datetime

currentYear = datetime.date.today().year

def heartbeats(age):

av = 72 * 60 * 24 * 365

for i in range(currentYear - age - 1, currentYear + 1):

if is_leap(i):

av += av

else:

pass

return av

def yawns(age):

av = 5 * 365

for i in range(currentYear - age - 1, currentYear + 1):

if is_leap(i):

av += av

else:

pass

return av

def is_leap(year):

if (( year%400 == 0)or (( year%4 == 0 ) and ( year%100 != 0))):

return True

else:

return False

print("Heartbeats: {}, yawns: {}".format(heartbeats(23),yawns(23)))

Step-by-step explanation:

We have defined 3 functions:

  • def heartbeats(age): Takes the average heartbeats of a year and sum a acumulative varible(av) when the year is not leap. Return av value.
  • def yawns(age): Takes the average yawns of a year and sum a acumulative variable(av) when the year is not leap. Return av value.
  • def is_leap(year): Return true if is a leap year and false if not.
  • print("Heartbeats: {}, yawns: {}".format(heartbeats(23),yawns(23))). Print the output of the called functions(heartbeats and yawns) for the inserted age (23).
User Timur Ridjanovic
by
5.2k points