首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“‘While”循环计数是否有效?

“‘While”循环计数是否有效?
EN

Stack Overflow用户
提问于 2013-08-20 18:33:13
回答 1查看 171关注 0票数 0
代码语言:javascript
复制
ans = num_rushes(100, 15, 7)
print(ans) 

应该返回19,但我的返回12?

这就是我所拥有的:

代码语言:javascript
复制
def num_rushes(slope_height, rush_height_gain, back_sliding):
    rushes = 0
    current_height = 0
    rush_height_counter = 0
    back_sliding_counter = 0
    rush_height_gain = 0.95 ** rush_height_counter * rush_height_gain
    back_sliding = 0.95 ** back_sliding_counter * back_sliding

    while current_height < slope_height:
        current_height = current_height + rush_height_gain
        rushes += 1
        rush_height_counter += 1
        back_sliding_counter += 1

        if current_height < slope_height:
            current_height = current_height - back_sliding

        else:
            return rushes
EN

回答 1

Stack Overflow用户

发布于 2013-08-20 19:55:03

使用这段代码0.95 ** rush_height_counter * rush_height_gain,您的意思是

代码语言:javascript
复制
0.95 ** (rush_height_counter * rush_height_gain)

代码语言:javascript
复制
(0.95 ** rush_height_counter) * rush_height_gain

我想你想要第一个,但是python (据我所知)做第二个!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18332817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档