以下是一个示例代码,演示如何比较响应200和要求答案为'true':
import requests
# 发送请求
response = requests.get('https://example.com/api')
# 检查响应状态码是否为200
if response.status_code == 200:
# 检查响应文本是否为'true'
if response.text == 'true':
print("响应为200且答案为'true'")
else:
print("响应为200但答案不为'true'")
else:
print("响应状态码不为200")
请注意,这只是一个示例代码,实际情况可能会有所不同。您需要根据您的具体需求和API响应的内容来进行修改。