473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. print "--------Welcome To The Heartbeat Program--------"
  2.  
  3. averagerate = input ("\nPlease enter your average heart rate:")
  4.  
  5. totalyears = input ("Please enter the total number of years:")
  6.  
  7. heartrate = 60 * 60 * 24 * 365.25 
  8.  
  9. result = averagerate * heartrate * totalyears
  10.  
  11. print "\nThe total heartbeats is:", "%.7d" % (result)
  12.  
  13. print "\n--------End Program--------"
Can someone help me then? Many thanks.
Dec 2 '08 #1
14 6013
bvdet
2,851 Expert Mod 2GB
I think an accepted heart rate is beats per minute (bpm). A general formula could therefore be written as a function as follows:
Expand|Select|Wrap|Line Numbers
  1. def heartbeats(rate, years):
  2.     return int(rate*60*24*365.25*years)
Now it's a matter of getting the input from the user and formatting the output.
Dec 2 '08 #2
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
Dec 2 '08 #3
bvdet
2,851 Expert Mod 2GB
Your code is almost there! Just substitute this line at the appropriate location:
Expand|Select|Wrap|Line Numbers
  1. result = heartbeats(averagerate, totalyears)
Dec 2 '08 #4
Curtis Rutland
3,256 Expert 2GB
@imran akhtar
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
Dec 2 '08 #5
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
Dec 3 '08 #6
Curtis Rutland
3,256 Expert 2GB
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.
Dec 3 '08 #7
Nevermind, I have come up with a solution. No, I am not a student. Bye.
Dec 3 '08 #8
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
File Type: txt heartbeat.txt (732 Bytes, 442 views)
Dec 17 '08 #9
Laharl
849 Expert 512MB
When using string formatting, the syntax is
Expand|Select|Wrap|Line Numbers
  1.  "string with % signs" % (values to replace the format specifiers)
You're missing the % in between.
Dec 17 '08 #10
bvdet
2,851 Expert Mod 2GB
You are missing the modulo operator in the print format code:
Expand|Select|Wrap|Line Numbers
  1. print "\nyour total heartbeats is:", "%.7d" % (result)
You have other problems. Your code:
Expand|Select|Wrap|Line Numbers
  1. print "--Welcome To The Heartbeat Program---"
  2.  
  3. def heartbeats(rate, years): 
  4.     return int(rate*60*24*365.25*years)
  5.  
  6. rate = input ("\nWhat isaverage heart rate:")
  7.  
  8. years = input ("Enter total number of years:")
  9.  
  10. heartbeat = 60 * 60 * 24 * 365.25
  11.  
  12. result = rate * rate * years
  13.  
  14. #result = averagerate * heartrate * totalyears
  15.  
  16. print "\nyour total heartbeats is:", "%.7d" (result)
  17.  
  18. 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:
Expand|Select|Wrap|Line Numbers
  1. number_beats = rate*60*24*365.25
See how the units cancel out and you end up with only beats:
Expand|Select|Wrap|Line Numbers
  1. '''
  2. beats     minute     hour     day
  3. ------ * -------- * ------ * ------ * year = beats
  4. minute    hour       day      year
  5. '''
You define function heartbeats(), but you do not use it. HTH
Dec 17 '08 #11
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
File Type: txt heartbeat.txt (706 Bytes, 469 views)
Dec 17 '08 #12
bvdet
2,851 Expert Mod 2GB
You have an error:
Expand|Select|Wrap|Line Numbers
  1. result = rate * rate * years
If you are not going to use function heartbeats(), why don't you delete it?

-BV
Dec 17 '08 #13
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.
Dec 17 '08 #14
bvdet
2,851 Expert Mod 2GB
For a heart rate of 60 beats per minute, I calculate 31557600 heart beats in one year.

-BV
Dec 17 '08 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
28
by: Jed | last post by:
Hello to all! I have a couple of projects I intend starting on, and was wondering if someone here could make a suggestion for a good compiler and development environment. My goals are as...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
2
by: Jet Leung | last post by:
When I debug my program and it return me an error call " have not handle ¡°System.StackOverflowException¡± appear in system.windows.forms.dll " How can I solve this problem??
7
by: satish | last post by:
how to write script for these 1.Given a test file containing lines of words such as (abc, abb, abd,abb, etc), write a script that prints, in order of frequency, how many times each word appears...
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.