Page 251 - CTS - CSA TP - Volume 2
P. 251

COMPUTER SOFTWARE APPLICATION - CITS


           EXERCISE 124 : Determine the sequence of execution

                                        based on operator precedence


            Objectives

           At the end of this exercise you shall be able to
           •  develop python program to determine the sequence of execution based on operator precedence
           Requirements


           Tools/Materials
           •  PC/Laptop  with Windows OS
           •  Latest Version of Python


           Procedure

           TASK 1: Arithmetic Operations
              Code:

              # Program to demonstrate arithmetic operations based on precedence
              num1 = float(input(“Enter the first number: “))
              num2 = float(input(“Enter the second number: “))
              result = num1 * (num2 + 3) / 2
              print(“Result:”, result)

              Output:












           TASK 2: Comparison and Logical Operators
           Code:
           # Program to demonstrate comparison and logical operators based on precedence
           x = int(input(“Enter a number: “))
           y = int(input(“Enter another number: “))

           result = x > 0 and (y % 2 == 0 or y > 10)
           print(“Result:”, result)
           Output:
















                                                           236
   246   247   248   249   250   251   252   253   254   255   256