global - 引用变量时出现问题 - 可能是全局状态问题
问题描述
以下代码位于循环多次(由 t 定义)的函数定义中。在任何后续时间 t > 1,我想查看当前价格是否比起始价格低 20% 或更多。但是,我收到“分配前引用的局部变量”错误,因为 if 语句中的 start_price 有问题。我也尝试在多个地方使用“global start_price”。任何想法或想法都会有所帮助。
if t = 1:
start_price = a / b
current_price = a / b
if current_price / start_price <= 0.80:
print("Price has dropped 20% or more")
解决方案
推荐阅读
- reactjs - 使用 Docusaurus 自定义内联脚本
- r - 使用 Rselenium 从新选项卡下载文件时出现问题
- css - 如何在材质ui TableBody内将div拉伸到100%宽度
- python - 有没有办法继续将文件中的额外列添加到pyspark中的“其他”列?
- angular - 有没有可能以角度获得服务器时间
- shell - julia shell 命令 tar 和 pigz
- elasticsearch - 用于计算 API 的 http 状态百分比的 Elasticsearch 查询
- reactjs - 未处理的拒绝(TypeError):无法读取未定义的属性“值”
- java - Grails g:远程链接注销按钮不起作用
- javascript - 如何以编程方式更改溢出和高度