I have written this code in python which is working but when I tried to write that same program by using functions it's impossible. Help me! This is the code which is working :
count=0
total=0
while True:
try:
itervar=raw_input('Enter a number: ')
if itervar == 'done':
break
itervar=float(itervar)
count=count+1
total=total+itervar
average=total/count
except:
print 'Invalid input'
print total, ' ' , count, ' ' , average
This is not working :
def count(itervar):
count = count+1
return count
def total(itervar):
total = total+itervar
return total
def average(count,total):
z=total/count
return z
count=0
total=0
while True:
try:
itervar=raw_input('Enter a number: ')
if itervar == 'done':
break
itervar=float(itervar)
count=count(itervar)
total=total(itervar)
except:
print 'Invalid input'
print total, ' ' , count, ' ' , average(count,total)
count()andtotal()and set them up to receive the same.count1andtotal1aren't defined before they are used.