Hey guys, the problem is asking the following:
Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!
Note: You do not need to provide assertEqual statements for this function.
For example:
Test
Input
Result
print(running_average()
3
5
done
4
The following is my code:
Incorrect - you should initialize your return value to 0
I have no idea what I did wrong. Thanks for the help
Use the Design Recipe to write a function called running_average that repeatedly asks the user to input integers at the keyboard until they type the word done. Return the average of the values they entered. You may assume the user will only enter integers or "done". Include a docstring!
Note: You do not need to provide assertEqual statements for this function.
For example:
Test
Input
Result
print(running_average()
3
5
done
4
The following is my code:
def running_average(): running_average = input("Enter an interger") total=0 num=0 while running_average !="done": total=int(running_average) + total num += 1 running_average=input("Enter an integer") if num == 0: return 0 else: running_average=total/num return running_averageBut I keep getting the following error :
Incorrect - you should initialize your return value to 0
I have no idea what I did wrong. Thanks for the help