Page 347 - Information_Practice_Fliipbook_Class11
P. 347

Program 12: Write a program that accepts a string, and forms a new string that contains only three lettered words,
            with space between each word. Display both strings.


            Ans.  '''
                    Objective: To accept a number and display sum of squares of all odd numbers
                   till that number

                   Input Parameter : num – numeric value
                   Return Value : sum of squares
                   '''


                   num = int(input("Enter a number : "))
                   sum = 0
                   for a in range(0,num + 1,2):
                       sum += a * a

                   print("The sum is ", sum)
            Program 13: Write a program that prints the message entered by the user.


            Ans. '''
                 Objective: To calculate octal equivalent of decimal number
                 Input: decNum – numeric value
                 Output: Octal equivalent of decNum
                 '''

                 dNum = int(input("Enter the decimal number: "))
                 octalEquivalent = ""
                 num = dNum


                 while dNum >= 1:
                     octalEquivalent = str(dNum % 8) + octalEquivalent
                     dNum //= 8


                 print("The octal equivalent of", num, "is:", octalEquivalent)
            Program 14: Write a program that prints the message entered by the user.

            Ans. '''

                 Objective: To input a welcome message and display it
                 Input: message
                 Output: message

                 '''
                 message = input(" Enter a welcome message : ")
                 print("You entered : ")
                 print(message)



                                                                                                      Practical  333
   342   343   344   345   346   347   348   349   350   351   352