Page 108 - Trackpad_V4.0_C8_Flipbook
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)
Premium Edition-VIII
106

