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

Type Error in python: I entered an integer type to add with an integer, but it gave an error [duplicate]

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

Ali Sohrabpour

Guest
Code:
average = 0
count = 0
while True:
    scores = 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: 
90
Traceback (most recent call last):
  File "d:\exzam.py", line 5, in <module>
    if scores < 0:
       ^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'

I expected the score input to be added to the average variable; because both are int types
<pre><code>average = 0
count = 0
while True:
scores = 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:
90
Traceback (most recent call last):
File "d:\exzam.py", line 5, in <module>
if scores < 0:
^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'
</code></pre>
<p>I expected the score input to be added to the average variable; because both are int types</p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top