Python While/For循环 [英] Python While/For loop

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

问题描述

我如何使它进入while循环并输出相同的内容??

how can I make this into a while loop and output the same thing????

for x in range(56,120) :
    if (x < 57) :
          summation = 0
    summation = x + summation
    if (x == 119) :
          print ("Sum of integers from 56 to 120 is", summation)

推荐答案

summation = 0
start_val = 56
stop_val  = 120
while start_val < stop_val:
    summation += start_val
    start_val += 1
print summation

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

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