Help with a heartbeat program

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • bvdet
    replied
    For a heart rate of 60 beats per minute, I calculate 31557600 heart beats in one year.

    -BV

    Leave a comment:


  • imran akhtar
    replied
    no it now runs, and outputs answer, but i want to know if you can double cheack, and see if it is the correct answer.

    Leave a comment:


  • bvdet
    replied
    You have an error:
    Code:
    result = rate * rate * years
    If you are not going to use function heartbeats(), why don't you delete it?

    -BV

    Leave a comment:


  • imran akhtar
    replied
    heart beat

    yeh thanks it now runs, but how do i know it works, baically i have sent attched txt file, so you can double cheack if it fucntion correctly with correct figures.

    once agian thanks for the help
    Attached Files

    Leave a comment:


  • bvdet
    replied
    You are missing the modulo operator in the print format code:
    Code:
    print "\nyour total heartbeats is:", "%.7d" % (result)
    You have other problems. Your code:
    Code:
    print "--Welcome To The Heartbeat Program---"
    
    def heartbeats(rate, years): 
        return int(rate*60*24*365.25*years)
    
    rate = input ("\nWhat isaverage heart rate:")
    
    years = input ("Enter total number of years:")
    
    heartbeat = 60 * 60 * 24 * 365.25
    
    result = rate * rate * years
    
    #result = averagerate * heartrate * totalyears
    
    print "\nyour total heartbeats is:", "%.7d" (result)
    
    print "\n----End Program----"
    You should clarify what the heart rate is. Let us assume the rate should be in units of beats per minute. There are 60 minutes in an hour, 24 hours in a day, and 365.25 days in a year. The calculation for the total number of beats is:
    Code:
    number_beats = rate*60*24*365.25
    See how the units cancel out and you end up with only beats:
    Code:
    '''
    beats     minute     hour     day
    ------ * -------- * ------ * ------ * year = beats
    minute    hour       day      year
    '''
    You define function heartbeats(), but you do not use it. HTH

    Leave a comment:


  • Laharl
    replied
    When using string formatting, the syntax is
    Code:
     "string with % signs" % (values to replace the format specifiers)
    You're missing the % in between.

    Leave a comment:


  • imran akhtar
    replied
    heartrate

    made the chagnes wht you have suggested , but getting problems such as: does not sems to totla up.

    below is the error message :
    (print "\nyour total heartbeats is:", "%.7d" (result)
    TypeError: 'str' object is not callable
    Attached Files

    Leave a comment:


  • imran akhtar
    replied
    Nevermind, I have come up with a solution. No, I am not a student. Bye.

    Leave a comment:


  • Curtis Rutland
    replied
    You have just repeated your problem....you still haven't explained why you need two different sets of code to do the exact same thing.

    Please explain.

    Leave a comment:


  • imran akhtar
    replied
    heart beatcode

    no i need another code, due to the fact i have to make two diffrent codes which does the same thing, i have one code which already works, but need another one, which i am struggling to come up with.

    if any one can come up with another code, which does the same thing, that will be great, or give any hints to write seconde the code.

    many thanks

    Leave a comment:


  • Curtis Rutland
    replied
    Originally posted by imran akhtar
    ... but i need another soloution to the code which, does same thing, but has to be written diffrently to the one i have done...
    I must wonder why you would need to re-write some code in a different way...the only thing I can think of is that you're a student either helping someone, or having them help you...

    If I am wrong in this assumption, I apologize in advance, but we don't help with homework, especially not re-writing homework so that it looks different.

    MODERATOR

    Leave a comment:


  • bvdet
    replied
    Your code is almost there! Just substitute this line at the appropriate location:
    Code:
    result = heartbeats(averagerate, totalyears)

    Leave a comment:


  • imran akhtar
    replied
    heartbeat

    the heart beat code works fine, but i need another soloution to the code which, does same thing, but has to be written diffrently to the one i have done

    many thanks

    Leave a comment:


  • bvdet
    replied
    I think an accepted heart rate is beats per minute (bpm). A general formula could therefore be written as a function as follows:
    Code:
    def heartbeats(rate, years):
        return int(rate*60*24*365.25*years)
    Now it's a matter of getting the input from the user and formatting the output.

    Leave a comment:


  • imran akhtar
    started a topic Help with a heartbeat program

    Help with a heartbeat program

    Hi. I have created a program which works correctly, and was just wondering if someone could help me in writing another program which works in the same way, but if the code is different. Below is what the program has to do:

    If a human heartbeats on average once a second for 78 years, how many times does the heart beat in a lifetime? (use 365.25 days per year). Re-write your program to prompt the user to input an average rate and total number of years and output the resulting heart beats in a lifetime.
    This is the program I have created:

    Code:
    print "--------Welcome To The Heartbeat Program--------"
    
    averagerate = input ("\nPlease enter your average heart rate:")
    
    totalyears = input ("Please enter the total number of years:")
    
    heartrate = 60 * 60 * 24 * 365.25 
    
    result = averagerate * heartrate * totalyears
    
    print "\nThe total heartbeats is:", "%.7d" % (result)
    
    print "\n--------End Program--------"
    Can someone help me then? Many thanks.
Working...