Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 146 - CodePilot V5.0 C7
P. 146

    Program 15 To print only odd numbers, skip any even number.

                          Program15.py
                       File  Edit  Format   Run    Options   Window    Help

                       for i in range(1, 11):
                           if i % 2 == 0:
                               continue  # skip even numbers
                           print("Odd number:", i)
                       print("Out of for loop")

                          Output
                                                                                                  SHORT SIGN
                       Odd number: 1
                       Odd number: 3
                       Odd number: 5                                                              To select all text:
                       Odd number: 7
                                                                                                       Ctrl + A
                       Odd number: 9
                       Out of for loop

                                                                 Ask
                                                                           AGENT
                                                            OrangeAI
                        Write Python code to illustrate jump statements like break, continue and pass.

                               Study

                             SOME MORE PROGRAMS

                       Program 16 To find the average of the first 10 natural numbers.

                          Program16.py

                       File  Edit  Format   Run    Options   Window    Help
                       total = 0
                       for i in range(1, 11):
                           total += i
                       average = total / 10
                       print("Average of first 10 natural numbers is:", average)

                          Output

                       Average of first 10 natural numbers is: 5.5

                       144
                            CodePilot (V5.0)-VII

| 141 142 143 144 145 146 147 148 149 150 151 |