Page 8 - PYTHON-12
P. 8

Ans.  The correct code is as follows:

                 def check_num():
                         num = input("Enter a number:")
                         if (abs(num)== num):
                              print("You entered a positive number)"
                         else:
                              num*=-1
                              print__("Number made positive:",num)
                 check_num()
              27.   I.  (a)  What constraint should be used to ensure that a column contains unique values but must not
                         accept NULL entries?                                                               (2)
                                                            OR
                      (b)  What constraint can be applied to a table column to ensure that all entries meet a specific condition
                         such as allowing only positive numbers?
                  II.  (a)  Write the SQL command to create a unique constraint on the Marks column in a table named Student.
                                                            OR
                      (b)  Write the SQL command to make the column Product_ID the primary key of an already existing table,
                         named PRODUCT.
             Ans.   I.  (a)  Primary Key constraint
                                                            OR
                      (b)  Check constraint
                  II.  (a)  ALTER TABLE Student
                        ADD CONSTRAINT UNIQUE (Marks);
                                                            OR
                      (b)  ALTER TABLE PRODUCT

                        ADD PRIMARY KEY (Product_ID);
              28.  (a)  List one advantage and one disadvantage of bus topology.                            (2)
                                                            OR
                  (b)  What does WAN stands for? Describe.
             Ans.  (a)  One advantage of bus topology is that nodes can be connected or removed easily from bus network.
                      One disadvantage of bus topology is that if there is a fault or breakdown of the backbone (main cable), the
                     entire network shuts down.
                                                            OR
                  (b)  WAN stands for Wide Area Network.
                      It is a telecommunication network that spreads over a large geographical area across countries and
                     continents. It facilitates fast and efficient exchange of information at high speed and low cost, for
                     example, the internet.

                                                         Section C
              29.  (a)  Write a Python function called Replace_ Word(filename, old_word, new_word) that takes three
                     parameters: filename (string), old_word (string) and new_word (string). The function should replace
                     all occurrences of old_word with new_word in the specified file.                       (3)
                                                            OR
                  (b)  Write a Python function called Unique_Words(filename) that takes a single parameter, filename (string).
                     The function should read the content of the specified file and return a set of unique words.
             Ans.  (a)  def Replace_Word_in_file(filename, old_word, new_word):
                         try:
                            with open(filename, 'r') as file:
                           content = file.read()
                            content = content.replace(old_word, new_word)
                            with open(filename, 'w') as file:
                           file.write(content)
                         except FileNotFoundError:
                            return "File not found."
                     Note: Users can take any filename, old word and new word.

                       Appendices                                                                          A.39
   3   4   5   6   7   8   9   10   11   12   13