Page 515 - Computer Science V2.0 Class 11
P. 515

Return Value : None
                         '''

                         bytes = sizeInBits // 8
                         nibbles = sizeInBits // 4
                         print(f"Memory in bits: {sizeInBits} bits")
                         print(f"Memory in bytes: {bytes} bytes")
                         print(f"Memory in nibbles: {nibbles} nibbles")



                     sizeInBits = int(input("Enter the size of memory in bits: "))
                     convertMemory(sizeInBits)


                 Program 21: Write a program to display the area and perimeter of a rectangle. Define two separate functions, returning
                 area and perimeter of a rectangle, respectively, for the user-inputted length and breadth.


                 Ans. def rectangleArea(length, width):
                         '''
                         Objective : To calculate the area of a rectangle
                         Input Parameter : length , width – numeric value
                         Return Value : length * width – numeric value

                         '''
                         return length * width


                     def rectanglePerimeter(length, width):

                         '''
                         Objective : To calculate the perimeter of a rectangle
                         Input Parameter : length , width – numeric value
                         Return Value : 2*(length + width) – numeric value
                         '''
                         return 2 * (length + width)



                     length = float(input("Enter the length of the rectangle: "))
                     width = float(input("Enter the width of the rectangle: "))
                     area = rectangleArea(length, width)

                     perimeter = rectanglePerimeter(length, width)
                     print(f"Area of the rectangle: {area}")
                     print(f"Perimeter of the rectangle: {perimeter}")
                 Program 22: Define two separate functions, returning volume and surface area of a sphere, respectively, for the
                 user-inputted radius.

                 Ans. import math

                     def sphereVolume(radius):


                                                                                                           Practical  501
   510   511   512   513   514   515   516   517   518   519   520