Programming and Problem Solving Through Python Language Theory Question

Modules - Set 2

  1. A Python module is a file with the __________ file extension that contains valid Python code.
    1. .pymodule
    2. .module
    3. .py
    4. .pym
    Answer : C
    Explain : In Python, Modules are simply files with the “. py” extension containing Python code that can be imported inside another Python Program.
  2. Which module to be imported to make the following line functional ?
    sys.stdout.write(“ABC”)
    1. system
    2. stdin
    3. stdout
    4. sys
    Answer : D
    Explain : The python sys module provides functions and variables which are used to manipulate different parts of the Python Runtime Environment.
  3. What will be the output of following code ?
    import math
    print(math.sqrt(36))
    1. Error
    2. -6
    3. 6.0
    4. 6
    Answer : C
    Explain : It gives value in float point which is 6.0
  4. What will be the output of the following Python code ?
    from math import sqrt
    print(math.sqrt(25))
    1. 5
    2. 5.0
    3. Error, the statement should be: print(sqrt(25))
    4. Error, sqrt mehtod does not exists
    Answer : C
    Explain : We need to get square root of 25, So we use print(sqrt(25)).
  5. What does os.getlogin() return ?
    1. name of the current user logged in
    2. gets a form to login as a different user
    3. name of superuser
    4. All of above
    Answer : A
    Explain : The os. getlogin() method returns the name of the user logged in to the terminal.
  6. Which of these definitions correctly describes a module ?
    1. Denoted by triple quotes for providing the specification of certain program elements
    2. Design and implementation of specific functionality to be incorporated into a program
    3. Defines the specification of how it is to be used
    4. Any program that reuses code
    Answer : B
  7. What will be the output of the following Python code ?
    from math import *
    ceil(3.4)
    1. 3
    2. 3.0
    3. 4
    4. 4.0
    Answer : C
    Explain : Ceil() mehtod gives the rounded value which is greater than given value (x).
  8. Which of the following number can never be generated by the following code :
    random.randrange(0, 50)
    1. 0
    2. 1
    3. 49
    4. 50
    Answer : D
    Explain : 50 is not generated because it is stopping value.
  9. Which of the following is a standard Python module that provides mathematical functions?
    1. math
    2. calculation
    3. arithmetic
    4. number
    Answer : A
    Explain : Python has a built-in module name - math module that you can use for mathematical tasks.
  10. What is the purpose of the 'as' keyword when importing a module in Python ?
    1. It imports a module.
    2. It defines a new module.
    3. It renames the module for easier reference.
    4. It excludes the module from the program.
    Answer : C
    Explain : as in module is used to rename the module according the choice of user.

Next Set

1