Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Print Numbers from 1 to 10

Print one through ten with a for loop. Beginners trace range boundaries, repeated print calls, and the excluded stopping value without reading user input.

BeginnerPhase 2 - Level 1: Basic LoopingExample 1 of 14
print-numbers-from-1-to-10.py
1# Print numbers 1 to 10
2for i in range(1, 11):
3 print(i)

Output

1
2
3
4
5
6
7
8
9
10

In this one

  • Read range bounds
  • Trace repeated output
  • Understand excluded stops

How it works

  1. 1

    Create range(1, 11).

  2. 2

    Assign each supplied value to i.

  3. 3

    Print i with its default newline.

Edge cases

Is eleven printed?

Is eleven printed?

No. range excludes its stop value.

Is input required?

Is input required?

No. Both bounds are written directly in the code.

What's going on

range(1, 11) supplies the integers one through ten. Each value is assigned to i before the indented print runs.

The stop value eleven is excluded. print adds a newline each time, so this is ten separate lines, not a single string containing a range. Moving print outside the loop would change the result completely.

Is eleven printed? No. range excludes its stop value.

Is input required? No. Both bounds are written directly in the code.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

How often does print run?

Pick an answer to check it.

Question 2

Is eleven printed?

Pick an answer to check it.

Questions people ask

Is eleven printed?

No. range excludes its stop value.

Is input required?

No. Both bounds are written directly in the code.

How often does print run?

Ten times.