Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+1 vote

I'd like to print all the even numbers from 2 to 10, including 10 itself.

Here's my code:

for i in range(2,10):
    print(i)

It's not working because it prints odd numbers too, and doesn't print 10 -- can you help me out?

asked in CSC201 Spring 2025 by (280 points)

1 Answer

+2 votes

I got you fam :)

for i in range(2,11,2):
     print(i)

range doesn't include the last number and the extra number at the end is the set value for what it should be counted up by - according to Dr. Stonedahl from class.

answered by (117 points)
...