PCAP: Python Essentials 1 – Part 1 Summary Test

PCAP: Python Essentials 1 – Part 1 Summary Test
pcap summary test 1 ans


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 is the output of the following snippet?

    tup = (1, 2, 4, 8)
    tup = tup[-2:-1]
    tup = tup[-1]
    print(tup)
    • 44
    • 4
    • (4)
    • (4,)
  2. Assuming that my_tuple is a correctly crated tuple, the fact that tuples are immutable means that the following instruction:

    my_tuple[1] = my_tuple[1] + my_tuple[0]
    • may be illegal if the tuple contains strings
    • is illegal 
    • can be executed if and only if the tuple contains at least two elements
    • is full correct
  3. Which of the following lines correctly. invoke the function defined below? (Select two answers)

    def fun(a, b, c=0):
        #Body of the function.
    • fun()
    • fun(0, 1, 2)
    • fun(b=0, a=0)
    • fun(b=1)
  4. The meaning of a positional argument is determined by:

    • its position within the argument list
    • its connection with existing variables
    • its value
    • the argument’s name specified along with its value
  5. What will happen when you attempt to run the following code?

    print(Hello, World)
    • The code will raise the AttributeError exception.
    • The code will raise the syntaxError exception.
    • The code will raise the ValueError exception.
    • The code will print Hello World to the console.
    • The code will raise the TyepError exception.
  6. The following snippet:

    def func(a, b):
        reeturn b ** a
    print(func(b=2, 2))
    • will output 4
    • will output None
    • will output 2
    • is erroneous
  7. The following snippet:

    def function_1(a):
         return None
    def function_2(a):
         return function_1(a) * functin_1(a)
    print(function_2(2))
    • will output 16
    • will crate a runtime error
    • will output 4
    • will output 2
  8. What is the output of the following snippet?

    def fun(x):
        if c % 2 == 0:
           return 1
        else:
           return 2
    print(fun(fun(2)))
    • 2None
    • 1
    • the code will cause a runtime error
    • 2
  9. What is the output of the following piece of code?

    print("a", "b", "c", sep="sep")
    • a b c
    • abc
    • asepbsepcsep
    • asepbsepc
  10. Which of the following sentences are true about the code? (Select two answers)

    nums = [1, 2, 3]
    vals = nums
    • nums and vals are different names of the same list 
    • vals is longer tha nums
    • nums and vals are different lists
    • nums has the same length as vals
  11. What is the output of the following snippet?

    my_list = [1, 2]
    for v in range(2):
        my_list.insert(-1, my_list[v])
    print(my_list)
    • [1, 2, 2, 2]
    • [1, 2, 1, 2]
    • [2, 1, 1, 2]
    • [1, 1, 1, 2]
  12. What is the output of the following snippet?

    dct = {}
    dct['1'] = (1, 2)
    dct['2'] = (2, 1)
    for x in dct.keys():
         print(dct[x][1], end="")
    • 21
    • (2,1)
    • 12
    • (1,2)
  13. What is the output of the following piece of code?

    x = 1 // 5 + 1 / 5
    print(x)
    • 0.0
    • 0
    • 0.4
    • 0.2
  14. What is the output of the following piece of code?

    x = 1
    y = 2
    x, y z = x, x, y
    z, y, z = x, y, z
    print(x, y, z)
    • 2 1 2
    • 1 2 2
    • 1 1 2
    • 1 2 1
  15. The result of the following division:

    1 // 2
    • is equal to 0.5
    • is equal to 0
    • is equal to 0.0
    • cannot be predicted
  16. What is the output of the following snippet?

    def fun(inp =2, out =3):
        return inp * out
    print(fun(out =2))
    • 4
    • 6
    • 2
    • the snippet is erroneous and will cause SyntaxError
  17. What is the expected behavior of the following program?

    foo = (1, 2, 3)
    foo.index(0)
    • The program will cause a ValueError exception.
    • The program will output 1 to the screen.
    • The program will cause a SyntaxError exception.
    • The program will cause a TypeError exception.
    • The program will cause an AttributeError exception.
  18. What is the output of the following snippet?

    def fun(x, y):
        if x == y:
           return x
        else: 
           return fun(x, y-1)
    print(fun(0,3))
    • 1
    • 2
    • the snippet will cause a runtime error 
    • 0
  19. How many element does the lst list contain?

    lst = [i for i in range(-1, -2)]
    • two
    • three
    • zero
    • one
  20. What is the output of the following piece of code if the user enters two lines containing 2 and 4 respectively?

    x = float(input())
    y = float(input())
    print(y **(1 / x))
    • 4.0
    • 2.0
    • 0.0
    • 1.0
  21. What is the output of the following code if the user enters a 0 ?

    try:
        value = input("Enter a value: ")
        print(int(value) / len(value))
    except ValueError:
        print("Bad input...")
    except ZeroDivisionError:
        print("Very bad input...")
    except TypeErrorq:
        print("Very very bad input...")
    except:
        print("Booo!")
    • Very bad input...
    • Very very bad input...
    • Bad input...
    • Booo!
    • 0.0
    • 1.0
  22. What is the output of the following snippet?

    dct = {'one': 'two', 'three': 'one', 'two': 'three'}
    v = dct['three']
    for k in range(len(dct)):
        v = dct[v]
    print(v)
    • two
    • ('one', 'two', 'three')
    • three
    • one
  23. What value will be assignment to the x variable?

    z = 0
    y = 0
    x = y < z and z > y or y > z and z < y
    • False
    • 0
    • 1
    • True
  24. What is the output of the following piece of the code if the user enter two lines containing 3 and 6 respectively? 

    y = input()
    x = input()
    print(x + y)
    • 36
    • 3
    • 63
    • 6
  25. Which of the following variable names are illegal and will cause the SystemError exception? (Select two answers)

    • print
    • in 
    • for
    • in
  26. What is the expected behavior of the following program?

    try:
       print(5/0)
       break:
    except:
       print("Sorry, something went wrong...")
    except(ValueError, ZeroDivisionError):
       print("Too bad...")
    • The program will cause a ValueError exception and output the following message Too bad...
    • The program will cause a SyntaxError exception
    • The program will cause a ValueError exception and output a default error message.
    • The program will raise an exception handle by the first except block.
    • The program will cause a ZeroDivisionError exception and output the following message: Too bad...
    • The program will cause a ZeroDivisionError exception and output a default error message.
  27. Take a look at the snippet and choose the true statement:

    nums = [1, 2, 3]
    vals = nums
    del vals[:]
    • the snippet will cause a runtime error 
    • vals is longer than nums
    • nums is longer than vals
    • nums and vals have the same length 
  28. What is the output of the following snippet?

    my_list = [x * x for x in range (5)]
    def fun(lst):
        del lst[lst[2]]
        return lst
    print(fun(my_list))
    • [0 , 1, 4, 9]
    • [0, 1, 4, 16]
    • [0, 1, 9, 16]
    • [1, 4, 9,  16]
  29. What is the output of the following snippet?

    dd = {"1": "0", "0": "1"}
    for x in dd.vals():
        print(x, end="")
    • 0 1
    • 1 0
    • 0 0
    • the code is erroneous(the dict object has no vals() method) 
  30. What is the output of the following piece of code if the user enters two lines containing 3 and 2 respectively?

    x = int(input())
    y = int(input())
    x = x % y
    y = y % x
    print(y)
    • 1
    • 3
    • 2
    • 0
  31. Which if the following snippets shows the correct way of handing multiple excepting in a single except clause?

    • except TypeError, ValueError, ZeroDivisinError:
      # Some code.
    • except: (TypeError, ValueError, ZeroDivisinError)
      # Some code.
    • except TypeError, ValueError, ZeroDivisinError
      # Some code.
    • except: TypeError, ValueError, ZeroDivisinError
      # Some code.
    • except: (TypeError, ValueError, ZeroDivisinError):
      # Some code.
    • except (TypeError, ValueError, ZeroDivisinError)
      # Some code.
  32. An operator able to check  two values are not equal is code as:

    • =/=
    • !=
    • <>
    • not ==
  33. What will be the output of the following snippet?

    a = 1
    b = 0
    a = a ^ b
    b = a ^ b
    a = a ^ b
    print (a, b)
    • 1 1
    • 0 0
    • 1 0
    • 0 1
  34. How many stars (*) will the following snippet send to the console?

    i  =0 
    while i < i + 2 :  
        i += 1   
        print("*")
    else:   
        print("*")
    • zero
    • the snippet will enter an infinite loop, printing one star per line
    • one
    • two
  35. How many hashes (*) will the following snippet sent to the console?

    lst = [[x for x in range(3)] for y in range(3)]
    for r in range(3):
        for c in rang(3):
           if lst[r][c] % 2 != 0:
             print("#")
    • nine
    • zero
    • three
    • six
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.