Page 103 - Code_GPT_Class_8
P. 103
Program 4: To print a pattern using for loop.
*
**
***
****
Program4.py Output
File Edit Format Run Options Window Help *
**
for i in range (1,5):
***
print("*"*i)
****
Program 5: To print multiplication table of number taken as input from user.
Program5.py
File Edit Format Run Options Window Help
#program to calculate multiplication table of a number
num= int(input('Enter a number: '))
for i in range (1, 11):
print (num, 'x',i,'=', num * i)
On running the above program, you will get the following output:
Output
Enter a number: 6
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
6 x 10 = 60
THE WHILE LOOP
The while loop executes a set of statements repeatedly, until the logical expression evaluates to false.
When the condition becomes false, the control comes out of the loop.
Loops in Python 101

