Page 108 - Code_GPT_Class_8
P. 108
SOME MORE PROGRAMS
Program 10: To print a pattern using while loop.
Program10.py
File Edit Format Run Options Window Help
#Program to show a pattern using while loop.
a = 5
while a>= 1:
print("@"*a)
a -= 1
On executing the above program, you will get the following output:
Output
@@@@@
@@@@
@@@
@@
@
Program 11: To add first five natural numbers.
Program11.py
File Edit Format Run Options Window Help
sum=0
a=1
while (a<=5):
sum=sum+a
a=a+1
print("the sum of the first five natural numbers is", sum)
CodeGPT (Ver. 4.0)-VIII
106

