Python Forum
Python Code error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python Code error (/thread-26964.html)



Python Code error - Riteshfrancis - May-20-2020

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)



RE: Python Code error - pyzyx3qwerty - May-20-2020

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?


RE: Python Code error - Riteshfrancis - May-21-2020

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.