Zakariya Islam
Zakariya Islam

Reputation: 21

python 3 TypeError: '>' not supported between instances of 'int' and 'str' in an if statment

Q_1 = input ('Name the organelles where protiens are synthesised? : ')
if Q_1 == 'ribosome':
    print ('correct')
    score = score + 1
else:
    print ('WRONG')

Q_2 = input ('Suggest why plant cells have a cell wall and animal cells don\'t ?: ')
if Q_2 == 'To control the flow of water and oxygen':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_3 = input ('True or false is bacteria an examples of a prokaryotic cell ?: ')
if Q_3 == 'true':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_4 = input ('True or false prokaryotes don\'t have a cell wall ?: ')
if Q_4 == 'true':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_5= input ('What is a stem cell?: ')
if Q_5 == 'An undifined cell':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_6 = input ('True or false there are embryonic stem cells?: ')
if Q_6 == 'true':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_7 = input ('What is diffusion?: ')
if Q_7 == 'The movment of gas particles from an area of high concentraction to low concentration':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_8 = input ('True or false having a greater surface area increase the rate of diffusion?: ')
if Q_8 == 'true':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1

Q_9 = input ('Define osmosis ?: ')
if Q_9 == 'The movment of water particles from an area of high to low concentration':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1


Q_10 = input ('True or false increasing temperature increases the rate of osmosis?: ')

if Q_10 == 'true':
    print ('correct')
    score = score + 1

else:
    print ('WRONG')
    score = score -1
int_score = int(score)

if int_score >'0':
    score = 0
    print (score)

This is a GCSE bio quiz I'm working on. I want to set the score to 0 if it goes into negative numbers.

Upvotes: 0

Views: 902

Answers (1)

N Chauhan
N Chauhan

Reputation: 3515

From what I can see, the variable int_score suggests it holds an integer and in your if statement you write:

if int_score < '0':
    ...

In this case, 0 is a string. You need to write it as an int so that it can be compared:

if int_score < 0:
    ...

As a side note, might I suggest that your algorithm for checking correct answers is not optimal as you have to input the exact answer to get it right. You may want to check for keywords like so:

Suppose the answer is photosynthesis produces glucose and oxygen, checking for ‘glucose’ and ‘oxygen’:

ans = input('what are the products of photosynthesis')
words = ans.split()
if all(word in words for word in ('glucose', 'oxygen')):
    print('correct!')
    score += 1
else:
    print('wrong!')

Upvotes: 2

Related Questions