python - 条件 if else 语句
问题描述
prices = [80, 102, 84, 41, 74, 55, 32, 77, 92, 40, 91, 26]
wealth = 5000
init_price = 100
buy = []
sell = []
x = 0
for i, v in enumerate(prices):
if (v > init_price):
buy = wealth + 1000
continue
else:
buy_1 = buy.append(buy - 1000)
continue`
我想遍历循环,每次价格高于初始价格时,我都会增加 1000 的财富。对于每次循环小于初始价格,我想从财富中减去 1000。然后我想在所有迭代之后找到最终值。有人能帮忙吗?
解决方案
像这样:
In [191]: for price in prices:
...: if price > init_price:
...: wealth += 1000
...: else:
...: wealth -= 1000
...:
In [192]: wealth
Out[192]: -5000
推荐阅读
- c# - C# UNITY Unicode 表情符号显示
- optimization - ORTools CP-Sat Solver Channeling Constraint 依赖于 x
- node.js - 我在 cpanel 上部署的 nuxt 项目有问题
- python - 带有 kivy python 的时钟
- c# - 将 IWebHostingEnvironment 注入被覆盖的方法
- c# - 关系类别与类别图片
- python - 实现列表和对象的碰撞
- nlp - 我正在研究电影情绪分析,但是代码,但我的代码中遇到了与处理单词相关的问题
- certificate - 在 NET 中验证从 Java 生成的签名 Xml
- python - 编写了一个代码,如果至少一个整数是偶数则返回 true,否则返回 false