Page 42 - PYTHON-12
P. 42

26.  The code provided below is intended to reverse the characters in a given string, with each character separated
                     by a hyphen (-). However, there are syntax and logical errors in the code. Rewrite it after removing all the
                     errors and underline all the corrections made.                                           (2)
                    def reverse_str(string)

                        rev_str = ""
                        for in range(len(string)-1, -1, -1)
                            rev_str += string[j] + '-'

                        return rev_str[0:-1]
                    result = reverse_str("Source Code")
                    print("Reversed string with hyphens:" result)
                 27.  (I)  (A)  Which constraint should be applied to a table column to ensure that a specified default value is
                             automatically assigned if no value is provided during insertion?                 (2)

                                                               OR
                         (B)  Which constraint should be used on a table column to ensure that only values from a specific range
                             are allowed in the column?
                     (II)  (A)  Write an SQL command to remove UNIQUE constraint from the column Username in a table named
                             USERS.

                                                               OR
                         (B)  Write an SQL command to add NOT NULL constraint to an existing column Email in the table USERS.
                 28.  (A)  List any four objectives of FTP.                                                   (2)

                                                               OR
                     (B)  List one advantage and one disadvantage of Infrared Transmission.


                                                            Section C

                 29.  (A)  Write a Python function that reads a text file "DocList.txt" and displays the total number of sentences
                        in the file (consider each line as a sentence).                                       (3)
                                                               OR
                     (B)  Write a Python function that reads ‘Novel.txt’ and displays the last 5 words from the file.

                 30.  You have a Stack named TaskStack that contains records of tasks. Each task record is represented as a list
                     containing task_id, task_name and priority.                                              (3)
                     Write  the following  user-defined functions  in  Python to perform  the specified  operations  on  the Stack
                     TaskStack:
                          (I)  push_task(TaskStack, new_task): This function takes the Stack ‘TaskStack’ and a new task record
                             ‘new_task’ as arguments and pushes the new task record onto the Stack.

                         (II)  pop_task(TaskStack): This function pops the topmost task record from the Stack and returns it. If
                             the stack is already empty, the function should display ‘Underflow’.

                         (III)   peep(TaskStack): This function displays the topmost element of the Stack without deleting it. If the
                             Stack is empty, the function should display ‘None’.
                                                               OR





                                                                                             Practice Paper   A.5
   37   38   39   40   41   42   43   44   45   46   47