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

COMPUTER SOFTWARE APPLICATION - CITS


           EXERCISE 123 : Write and test a python program to

                                        perform data and data type operations,

                                        string operations, date, input and output,
                                        output formatting and operators


            Objectives

           At the end of this exercise you shall be able to
           •  develop python program to perform data and data type operations, string operations, date, input and output,
             output formatting and operators

           Requirements

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

           Procedure

           TASK 1: Arithmetic Operators
              Code:
              # Arithmetic Operators

              num1 = 10
              num2 = 3124
              sum_result = num1 + num2
              difference_result = num1 - num2

              product_result = num1 * num2
              division_result = num1 / num2
              remainder_result = num1 % num2
              print(f”Sum: {sum_result}”)
              print(f”Difference: {difference_result}”)
              print(f”Product: {product_result}”)

              print(f”Division: {division_result}”)
              print(f”Remainder: {remainder_result}”)
              Explanation:
              •  Addition (+): Adds num1 and num2 together, resulting in 13.

              •  Subtraction (-): Subtracts num2 from num1, resulting in 7.
              •  Multiplication (*): Multiplies num1 and num2, resulting in 30.
              •  Division (/): Divides num1 by num2, resulting in approximately 3.33333.
              •  Modulus (%): Computes the remainder when num1 is divided by num2, resulting in 1.
              These are basic arithmetic operations showcasing how Python handles addition, subtraction, multiplication,
              division, and modulus operations. The results are then printed for each operation.
              Output:





                                                           230
   240   241   242   243   244   245   246   247   248   249   250