Page 111 - 2502_Pakistan-kifayat_C-8
P. 111

sum = a + b

                 print("The sum is:",sum)
                 Output:
                 The sum is: 15

                 Example 2: Check eligibility for voting

                 age = 25

                 if age >= 18:
                     print("You are eligible to vote.")

                 else:
                     print("You are not eligible to vote.")
                 Output:

                 You are eligible to vote.
                 Example 3: Finding the Largest of Two Numbers

                 a = 25

                 b = 30
                 if a > b:

                     print("The larger number is:", a)
                 else:

                     print("The larger number is:", b)
                 Output:
                 The larger number is: 30

                 Example 4: Checking Even or Odd Number

                 num = 7
                 if num % 2 == 0:

                     print(num, "is even number.")

                 else:
                     print(num, "is odd number.")
                 Output:

                 7 is odd number.

                 Example 5: Displaying Multiplication Table

                 num = 4

                 for i in range(1, 11):

                     print(num, "×", i, "=", num * i)





                                                                                              #Texture Programming 109
   106   107   108   109   110   111   112   113   114   115   116