Python While/For loop
问题 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) 回答1: summation = 0 start_val = 56 stop_val = 120 while start_val < stop_val: summation += start_val start_val += 1 print summation 回答2: There are various methods, but one of them is: x = 56 while x < 120: ... x += 1 回答3: sum = 0 x = 56 while x < 120: sum += x x += 1 print(sum)