Page 435 - Computer Science Class 11 With Functions
P. 435

principal = float(input("Enter the principal amount (P): "))

                 rate = float(input("Enter the rate of interest (R) as a percentage: "))
                 time = float(input("Enter the time period (T) in years: "))
                 simpleInterest(principal,rate,time)
            Program 19

            Write  a  function  inchesToFeet  that  accepts  the  length  in  inches  and  returns  the  length  in  feet.  Invoke
            inchesToFeet to compute the length in feet for the length in inches entered by the user.
            Ans. def inchesToFeet(lengthInches):

                     '''
                     Objective : To calculate feet from inches
                     Input Parameter : lengthInches - numeric value
                     Return Value : None

                     '''
                     lengthFeet = lengthInches / 12.0
                     return lengthFeet

                 lengthInches = float(input("Enter length in inches: "))
                 lengthFeet = inchesToFeet(lengthInches)

                 print(f"Length in feet is: {lengthFeet} feet")
            Program 20

            Write a function that takes the size of memory in bits as input parameter and displays the memory in bytes and
            nibbles. The value of memory in bits should be accepted from the user and then passed as an input parameter to the
            function. Invoke the function to print the size of memory in bytes and nibbles for the user-inputted memory size in bits.

            Ans. def convertMemory(sizeInBits):
                     '''
                     Objective : To calculate memory in bytes and nibbles
                     Input Parameter : sizeInBits – numeric value

                     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)









                                                                                                      Practical  433
   430   431   432   433   434   435   436   437   438   439   440