For a heart rate of 60 beats per minute, I calculate 31557600 heart beats in one year.
-BV
Help with a heartbeat program
Collapse
X
-
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:
-
You have an error:
If you are not going to use function heartbeats(), why don't you delete it?Code:result = rate * rate * years
-BVLeave a comment:
-
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 helpAttached FilesLeave a comment:
-
You are missing the modulo operator in the print format code:
You have other problems. Your code:Code:print "\nyour total heartbeats is:", "%.7d" % (result)
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: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----"
See how the units cancel out and you end up with only beats:Code:number_beats = rate*60*24*365.25
You define function heartbeats(), but you do not use it. HTHCode:''' beats minute hour day ------ * -------- * ------ * ------ * year = beats minute hour day year '''
Leave a comment:
-
When using string formatting, the syntax isYou're missing the % in between.Code:"string with % signs" % (values to replace the format specifiers)
Leave a comment:
-
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 callableAttached FilesLeave a comment:
-
Nevermind, I have come up with a solution. No, I am not a student. Bye.Leave a comment:
-
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:
-
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 thanksLeave a comment:
-
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.
MODERATORLeave a comment:
-
Your code is almost there! Just substitute this line at the appropriate location:Code:result = heartbeats(averagerate, totalyears)
Leave a comment:
-
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 thanksLeave a comment:
-
I think an accepted heart rate is beats per minute (bpm). A general formula could therefore be written as a function as follows:
Now it's a matter of getting the input from the user and formatting the output.Code:def heartbeats(rate, years): return int(rate*60*24*365.25*years)Leave a comment:
-
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:
This is the program I have created: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.
Can someone help me then? Many thanks.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--------"Tags: None
Leave a comment: