Python 根据数据打印输出的范围(if-then)语句
我希望该值根据指定范围内的值输出返回响应Python 根据数据打印输出的范围(if-then)语句,python,python-3.x,string,if-statement,range,Python,Python 3.x,String,If Statement,Range,我希望该值根据指定范围内的值输出返回响应 import requests import json import time url = 'https://api.gdax.com/products/BTC-USD/trades' res = requests.get(url) json_res = json.loads(res.text) print('val ', json_res[0]['price']) buy = range(32000, 36000) sell = range(39
import requests
import json
import time
url = 'https://api.gdax.com/products/BTC-USD/trades'
res = requests.get(url)
json_res = json.loads(res.text)
print('val ', json_res[0]['price'])
buy = range(32000, 36000)
sell = range(39000, 50000)
if json_res in buy:
print('Low')
elif json_res in sell:
print('Too High')
这是我正在寻找的输出的一个示例
val 38000.00002545
Too High
阅读评论行
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
price=int(float(json_res[0]['price'])//1)#从str转换为float到int(以匹配范围值)
打印('val',价格)
购买=范围(32000,39000)#我将最大范围更改为39000,因为当前BTC价格为38xxx
销售=范围(39000,50000)
如果价格为买入价:
打印(“低”)
elif销售价格:
打印('太高')
优点:
- 我仍然使用您的
语法范围
- 我警告你当前的BTC价格 阅读评论行
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
price=int(float(json_res[0]['price'])//1)#从str转换为float到int(以匹配范围值)
打印('val',价格)
购买=范围(32000,39000)#我将最大范围更改为39000,因为当前BTC价格为38xxx
销售=范围(39000,50000)
如果价格为买入价:
打印(“低”)
elif销售价格:
打印('太高')
优点:
- 我仍然使用您的
语法范围
- 我警告你当前的BTC价格
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
打印('val',json_res[0]['price'])
如果32000<浮动(val)<3600:
打印(“低”)
elif 39000<浮动(val)<50000:
打印('太高')
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
打印('val',json_res[0]['price'])
如果32000<浮动(val)<3600:
打印(“低”)
elif 39000<浮动(val)<50000:
打印('太高')
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
打印('val',json_res[0]['price'])
购买=范围(32000、36000)
销售=范围(39000,50000)
如果在购买中浮动(json_res[0]['price']):
打印(“低”)
出售中的elif浮动(json_res[0]['price']):
打印('太高')
其他:
如果浮动(json_res[0]['price'])50000:
打印('高于高')
其他:
打印('中间')
导入请求
导入json
导入时间
url='1〕https://api.gdax.com/products/BTC-USD/trades'
res=requests.get(url)
json_res=json.loads(res.text)
打印('val',json_res[0]['price'])
购买=范围(32000、36000)
销售=范围(39000,50000)
如果在购买中浮动(json_res[0]['price']):
打印(“低”)
出售中的elif浮动(json_res[0]['price']):
打印('太高')
其他:
如果浮动(json_res[0]['price'])50000:
打印('高于高')
其他:
打印('中间')
import requests
import json
import time
url = 'https://api.gdax.com/products/BTC-USD/trades'
res = requests.get(url)
json_res = json.loads(res.text)
print('val ', json_res[0]['price'])
if 32000 < float(val) < 3600:
print('Low')
elif 39000 < float(val) < 50000:
print('Too High')
import requests
import json
import time
url = 'https://api.gdax.com/products/BTC-USD/trades'
res = requests.get(url)
json_res = json.loads(res.text)
print('val ', json_res[0]['price'])
buy = range(32000, 36000)
sell = range(39000, 50000)
if float(json_res[0]['price']) in buy:
print('Low')
elif float(json_res[0]['price']) in sell:
print('Too High')
else:
if float(json_res[0]['price']) <32000:
print('Lower Than low')
elif float(json_res[0]['price']) >50000:
print('Higher Than high')
else:
print('In Between')