[Tutor] (no subject)
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Apr 15 11:23:40 CEST 2013
You've already had a sound answer from Dave Angel, I've just a few
comments below.
On 15/04/2013 01:35, Soliman, Yasmin wrote:
> Hi everyone. I just need to know why this programs tells me End is not defined, what can I o to fix this issue? Thanks in advance.
>
> hrList=[]
> while True:
> heartrate= float(input('Enter heart rate as beats per min: '))
> hrList.append(heartrate)
>
> if heartrate=='End':
> print '\nThank you for using this program! Bye.'
> break
>
> total_sum = 0;
No need for the semicolon.
> length = len(hrList)
> for i in range(0, length):
> total_sum += hrList[i]
For the third time in three days, you rarely need to write a loop like
this in Python :)
for hr in hrList:
total_sum += hr
>
> average = total_sum / length
Part of the learning curve, but the lot could be written as.
average = sum(hrList) / len(hrList)
>
> print average
>
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
More information about the Tutor
mailing list