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

Program 18: Write a program to accept the values of principal, rate, and time and calculate the simple interest.

              Ans. def simpleInterest(principal,rate,time):

                       '''
                       Objective : To calculate simple interest
                       Input Parameters :
                       principal- numeric value denoting principal amount
                       rate - numeric value denoting rate of interest in % per annum
                       time - numeric values indicating time period in years

                       Return Value : None
                       '''
                       rate /= 100
                       simple_interest = principal * rate * time

                       print(f"Simple Interest: {simple_interest:.2f}")

                   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


               500   Touchpad Computer Science (Ver. 2.0)-XI
   509   510   511   512   513   514   515   516   517   518   519