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

COMPUTER SOFTWARE APPLICATION - CITS




           EXERCISE 137 :   Solve complex computing problems by
                                         using builtin modules


            Objectives


           At the end of this exercise you shall be able to
           •  develop python programs  to Solve complex computing problems by using builtin modules.

           Procedure


           TASK 1: Finding the Square Root with the math Module
           Code:
           import math

           number = float(input(“Enter a number: “))
           square_root = math.sqrt(number)
           print(f”The square root of {number} is {square_root}”)
           Explanation:

           1  Importing the math Module:
           •  import math: This line imports the math module, which provides access to various mathematical functions and
              constants.
           2  Getting User Input:

           •  number = float(input(“Enter a number: “)): This line prompts the user to enter a number. The input is captured
              as a string using the input() function and then converted to a floating-point number using float().
           3  Calculating the Square Root:

           •  square_root = math.sqrt(number): This line calculates the square root of the input number using the sqrt()
              function from the math module.
           4.  Displaying the Result:

           •  print(f”The square root of {number} is {square_root}”): This line prints the calculated square root using an
              f-string. It displays the original number entered by the user along with its square root.
           Output:













           TASK 2: Calculating Trigonometric Functions with the math Module

           Code:
           import math
           angle = float(input(“Enter an angle in degrees: “))
           sin_value = math.sin(math.radians(angle))

           cos_value = math.cos(math.radians(angle))



                                                           301

 CITS : IT & ITES - Computer Software Application - Exercise 136
   311   312   313   314   315   316   317   318   319   320