๐ Python Code
# Example 16
# Print numbers from 1 to 10
for i in range(1,11):
print(i)
๐ค Python Output
1
2
3
4
5
6
7
8
9
10 โ
A fun beginner programming course for young programmers
Created by Geta Ba / GETCOM
Python repeats instructions using a for loop.
# Example 16
# Print numbers from 1 to 10
for i in range(1,11):
print(i)
1
2
3
4
5
6
7
8
9
10 โ
Python creates multiplication tables automatically.
number=int(input("Enter Number: "))
for i in range(1,11):
print(number,"x",i,"=",number*i)
Enter Number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 10 = 50 โญ
Python can calculate totals automatically.
total=0
for i in range(1,101):
total=total+i
print("Total =",total)
Total = 5050
Python calculates square values using loops.
for i in range(1,11):
print(i,"Square =",i*i)
1 Square = 1
2 Square = 4
3 Square = 9
10 Square = 100
Python uses loops to display only even numbers.
# Example 20
# Print Even Numbers from 1 to 20
for i in range(1,21):
if i % 2 == 0:
print(i)
2
4
6
8
10
12
14
16
18
20 โ
Python can create beautiful patterns using loops.
# Example 21
# Create Star Pattern
for i in range(1,6):
print("*" * i)
*
**
***
****
*****
Python decreases stars in every loop.
for i in range(5,0,-1):
print("*" * i)
*****
****
***
**
*
Python creates a centered pyramid shape.
for i in range(1,6):
print(" "*(5-i) + "*"*(2*i-1))
*
***
*****
*******
*********
Python combines two loops to create a diamond.
for i in range(1,6):
print(" "*(5-i)+"*"*(2*i-1))
for i in range(4,0,-1):
print(" "*(5-i)+"*"*(2*i-1))
*
***
*****
*******
*********
*******
*****
***
*
Python creates rows and columns using loops.
for i in range(5):
print("* "*5)
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Python can print numbers using loops.
for i in range(1,6):
for j in range(i):
print(i,end=" ")
print()
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5