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: - 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.
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: - 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.
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
bvdet 2,851
Expert Mod 2GB
Your code is almost there! Just substitute this line at the appropriate location: - result = heartbeats(averagerate, totalyears)
@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
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
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.
Nevermind, I have come up with a solution. No, I am not a student. Bye.
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
When using string formatting, the syntax is - "string with % signs" % (values to replace the format specifiers)
You're missing the % in between.
bvdet 2,851
Expert Mod 2GB
You are missing the modulo operator in the print format code: - print "\nyour total heartbeats is:", "%.7d" % (result)
You have other problems. Your 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: - number_beats = rate*60*24*365.25
See how the units cancel out and you end up with only beats: - '''
-
beats minute hour day
-
------ * -------- * ------ * ------ * year = beats
-
minute hour day year
-
'''
You define function heartbeats(), but you do not use it. HTH
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
bvdet 2,851
Expert Mod 2GB
You have an error: - result = rate * rate * years
If you are not going to use function heartbeats(), why don't you delete it?
-BV
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.
bvdet 2,851
Expert Mod 2GB
For a heart rate of 60 beats per minute, I calculate 31557600 heart beats in one year.
-BV
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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?
|
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...
|
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??
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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....
|
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
|
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...
| |