PCAP: Python Essentials 2 – Module 3 Test Answers

PCAP: Python Essentials 2 – Module 3 Test Answers.Learn programming from scratch and master Python. cisco free course answer 2022
PCAP answer


Python Essentials - Final Test:

Warning!
For searching questions, CTRL+F .if you want correct answer.. type manually.Don't Copy & paste questions in search space.
If you copy paste questions in search options means.. you can't find answer

 

  1. What will be the result of executing the following code?

    class Ex(Exception):
         def_init_(self,msg):
                Exception._init_(self,msg + msg)
                self.args = (msg,)
    
    try:
           raise Ex('ex')
    except Ex as e:
           print(e)
    except Exception as e:
           print(e)
    • it will print ex
    • it will print exex
    • it will print an empty line
    • it will raise an unhandled exception
  2. A data structure described as LIFO is actually a:

    • list 
    • stack
    • heap
    • tree
  3. What will be the output of the following code?

    class A:
        A = 1
    
    print(hasattr(A, 'A'))
    • 0
    • False
    • 1
    • True
  4. What will be the effect of running the following code?

    class A:
        def_init_(self,v):
            self._a = v + 1
    
    a = A(0)
    print(a._a)
    • 2
    • The code will raise an AttributeError exception
    • 0
    • 1
  5. What will be the result of executing the following code?

    class A:
        pass
    
    class B(A):
        pass
    
    class C(B):
         pass
    
    print(issubclass(C,A))
    • it will print 1
    • it will print False
    • it will print True
    • it will raise an exception
  6. What will be the result of executing the following code?

    class A:
        def_str_(self):
            return 'a'
    
    class B:
        def_str_(self):
            return 'b'
    
    class C(A, B):
         pass
    
    o = C()
    print(o)
    • it will print b
    • it will print c
    • it will print a
    • it will raise an exception
  7. What will be the result of executing the following code?

    class A:
        def a(self):
            print('a')
    
    
    class B: def a(self): print('b')
    class C(B,A):
    def c(self): self.a() o = C() o.c()
    • it will raise an exception
    • it will print a
    • it will print c
    • it will print b
  8. What will be the result of executing the following code?

    try:
       raise Exception(1,2,3)
    except Exception as e:
       print (len(e.args))
    • it will print 1
    • it will print 2
    • it will raise as unhandled exception
    • it will print 3
  9. What will be the output of the following code?

    class A:
       X = 0
       def __init__(self,v = 0):
           self.Y = v
           A.X += v
    a = A()
    b = A(1)
    c = A(2)
    print(c.X)
    • 2
    • 3
    • 0
    • 1
  10. If the class’s constructor is declared as below, which one of  the assignments is valid?

    class Class:
         def __init__(self):
             pass
    • object = Class
    • object = Class()
    • object = Class(self)
    • object = Class(object)
  11. What will be the result of executing the following code?

    def f(x):
        try:
            x = x / x
         except:
            print("a",end='')
         else:
            print("b",end='')
         finally:
            print("c",end='')
    f(1)
    f(0)
    • it will raise an unhandled exception
    • it will print bcac 
    • it will print acac
    • it will print bcbc 
  12. If there is a superclass named A and a subclass named B, which one of the presented invocations should you put instead of the comment?

    class A:
         def __init__(self):
            self.a = 1
    class B(A):
         def __init__(self):
             # put selected line here.
             self.b = 2
    • A.__init__(self)
    • __init__()
    • A.__init__()
    • A.__init__(1)
  13. What will be the result of executing the following code?

    class A:
         def__init__(self):
             pass
    a = A(1)
    print(hasattr(a,'A'))
    • 1
    • False
    • it will raise an exception
    • True
  14. What will be the result of executing the following code?

    class A:
    ​​​​     def__init__(self):
              return 'a'
    class B(A):
          def__init__(self):
               return 'b'
    class c(B):
          pass
    o = C()
    print(o)
    • it will print c 
    • it will print b
    • it will print a 
    • it will raise an exception
  15. What will be the output of the following code?

    class A:
         def__init__(self,v = 1):
             self.v =v
         def set(self,v):
             self.v = v
             return v
    a = A()
    print(a.set(a.v + 1))        
    • 2
    • 1
    • 3
    • 0
  16. What will be the result of executing the following code?

    class A:
          v = 2
    class B(A):
          v = 1
    class C(B):
          pass
    o =C()
    print(o.v)
    • it will raise an exception 
    • it will print 2
    • it will print an empty line
    • it will print 1
Python Essentials - Final Test:

Post a Comment

If you have any doubts, Ask here..,
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.