Python Forum
Intializing return value to 0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Intializing return value to 0
#1
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:
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_average
            
But 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
Reply


Messages In This Thread
Intializing return value to 0 - by adam10e10 - Apr-11-2019, 12:14 AM
RE: Intializing return value to 0 - by ichabod801 - Apr-11-2019, 02:14 AM
RE: Intializing return value to 0 - by loomski - Apr-11-2019, 05:43 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020