How is it possible to use a while loop to print even numbers 2 through 100?
问题 I am a beginner and I am stuck on this problem, "Write a python code that uses a while loop to print even numbers from 2 through 100. Hint ConsecutiveEven differ by 2." Here is what I came up with so far: while num in range(22,101,2): print(num) 回答1: Use either for with range() , or use while and explicitly increment the number. For example: >>> i = 2 >>> while i <=10: # Using while ... print(i) ... i += 2 ... 2 4 6 8 10 >>> for i in range(2, 11, 2): # Using for ... print(i) ... 2 4 6 8 10