Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 88 - 2611_SmartGPT Pro V(5.0) C-8
P. 88

    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)

                       86   Computer Science (V5.0)-VIII

| 83 84 85 86 87 88 89 90 91 92 93 |