For循环迭代2的幂 [英] For loop iterate over powers of 2

查看:121
本文介绍了For循环迭代2的幂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个for循环,该循环将为每个循环迭代2的幂.

I want to write a for loop that will iterate over the powers of 2 for each loop.

例如,我想要一个这样的范围:

For example I would want a range like this:

2, 4, 8, 16, ... , 1024

我该怎么办?

推荐答案

counter = 2

while counter <= 1024:
    print counter
    counter *= 2

这篇关于For循环迭代2的幂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆