gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:20:18 27 4
gpt4 key购买 nike

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)
这是我正在从事的GCSE生物学测验。
如果分数变为负数,我想将分数设置为0。

最佳答案

据我所知,变量int_score建议它包含一个整数,并在您的if语句中编写:

if int_score < '0':
...

在这种情况下, 0是一个字符串。您需要将其写为int以便可以进行比较:
if int_score < 0:
...

附带说明一下,我是否建议您检查正确答案的算法不是最佳算法,因为您必须输入准确答案才能正确回答。您可能要检查像这样的关键字:

假设答案是 photosynthesis produces 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!')

关于python - python 3 TypeError : '>' not supported between instances of 'int' and 'str' in an if statment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53249507/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com