OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I have an error in python: ValueError: invalid literal for int() with base 10: 'done'

  • Thread starter Thread starter Ali Sohrabpour
  • Start date Start date
A

Ali Sohrabpour

Guest
Code:
average = 0
count = 0
while True:
    scores = int(input('enter the scores: \n'))
    if scores < 0:
        continue
    elif scores == 'done':
        break
    else:
        average = scores + average
        count = count + 1
print(average / count)

Terminal:

Code:
enter the scores: 
20
enter the scores: 
40
enter the scores: 
60
enter the scores: 
done
Traceback (most recent call last):
  File "d:\exzam.py", line 4, in <module>
    scores = int(input('enter the scores: \n'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'done'

I want the while loop to break
<pre class="lang-py prettyprint-override"><code>average = 0
count = 0
while True:
scores = int(input('enter the scores: \n'))
if scores < 0:
continue
elif scores == 'done':
break
else:
average = scores + average
count = count + 1
print(average / count)
</code></pre>
<p>Terminal:</p>
<pre class="lang-none prettyprint-override"><code>enter the scores:
20
enter the scores:
40
enter the scores:
60
enter the scores:
done
Traceback (most recent call last):
File "d:\exzam.py", line 4, in <module>
scores = int(input('enter the scores: \n'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'done'
</code></pre>
<p>I want the while loop to break</p>
 

Latest posts

D
Replies
0
Views
1
Dhanushka Amarakoon
D
S
Replies
0
Views
1
Shikhar Ambashta
S
Top