小编A.L*_*run的帖子

while循环使用Python中的if/else语句

所以我仍然在学习Python,我很难处理while循环.我有一个代码示例,包括while循环ifelse语句.我想要它做的是打印'小于2'和'大于4'这样做,但它继续运行.它不打印一次,这是我想要它做的.任何帮助将不胜感激!

counter = 1
while (counter < 5):
    count = counter
    if count < 2:
        counter = counter + 1
    else:
        print('Less than 2')
    if count > 4:
        counter = counter + 1
    else:
        print('Greater than 4')
    counter = counter + 1 
Run Code Online (Sandbox Code Playgroud)

python if-statement while-loop

0
推荐指数
1
解决办法
4万
查看次数

标签 统计

if-statement ×1

python ×1

while-loop ×1