Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Code error
#1
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)
Reply


Messages In This Thread
Python Code error - by Riteshfrancis - May-20-2020, 09:40 AM
RE: Python Code error - by pyzyx3qwerty - May-20-2020, 09:59 AM
RE: Python Code error - by Riteshfrancis - May-21-2020, 06:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code error from Fundamentals of Python Programming van Richard L. Halterman Heidi 12 1,773 Jul-25-2023, 10:32 PM
Last Post: Skaperen
  Syntax error while executing the Python code in Linux DivAsh 8 1,747 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,630 Mar-27-2023, 07:38 AM
Last Post: buran
  Error in if-then-else python code Led_Zeppelin 6 2,436 Jul-27-2022, 07:53 PM
Last Post: deanhystad
  Facing error while executing below Python code ramu4651 1 5,800 Jan-26-2021, 06:40 PM
Last Post: ibreeden
  Skeleton file export error Python Code pepapoha 4 3,564 Nov-17-2020, 02:06 AM
Last Post: pepapoha
  Compiling Python 3.8.5 source code results in build error Deepan 0 2,208 Sep-14-2020, 04:11 AM
Last Post: Deepan
  Syntax error in python code sample ErnestTBass 5 3,160 Aug-14-2020, 07:14 PM
Last Post: deanhystad
  Error in Python Code ErnestTBass 4 2,788 Jun-04-2020, 05:28 PM
Last Post: buran
  Simple python code error cls0724 5 3,385 Mar-12-2020, 07:45 PM
Last Post: stullis

Forum Jump:

User Panel Messages

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