Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2629_Devagiri_C-8
P. 93

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

                         Program8.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 9 To find the average of the first 10 natural numbers.

                         Program9.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

                                                                                                                      91
                                                                                                   Networks Around Us

| 88 89 90 91 92 93 94 95 96 97 98 |