Python Forum

Full Version: Python Code error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Friends:

Can someone please help me and tell me what is wrong with follwing code of mine. After entering the input, system is coming out of the loop and executing last two lines.

count = 0
tot = 0

while True :

    num = input('Enter a number: ')

    if num == 'Done':
        break

    try:
            nm = float(num)
            count = count+1
            tot = tot + nm

    except:
            print ('Invalid Entry')
            continue

print(tot/count)
I don't understand your problem. I ran the code and here's the output
Output:
Enter a number: 5 Enter a number: Done 5.0
If this not your expected output, then can you please explain what are you trying with the code?
Hellos Sir,

I was trying to get the average of numbers entered in the loop. My code was not working before but later it worked.

Thank you for your reply.