我有以下算法:
if <some1>:
h += 1
elif <some2>:
h += 0.5
i += 1
else:
i += 1
是否可以只执行一次i += 1
?
最佳答案
我认为你想要表达的逻辑是:
if <some1>:
h += 1
else:
i += 1
if <some2>:
h+= 0.5
尽管它并不能为你节省很多。
关于algorithm - 如何从if语句中选择重复的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46280078/