SEM 3_PYTHON_COMBINED

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

13:What is the expected output of the following code? from datetime import datetime datetime = datetime(2019, 11, 27, 11, 27, 22) print(datetime.strftime("%y/%B/%d %H:%M:%s")) A) 19/November/27 11:27:22 B) 2019/Nov/27 11:27:22 C) 2019/11/27 11:27:22 D) 19/11/27 11:27:22

Answer: A

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)) A) 2 B) 1 C) 3 D) 0

Answer: A

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) A) it will print ex B) it will print exex C) it will print an empty line D) it will raise an unhandled exception

Answer: A

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)) A. [0, 1, 4, 9] B. [0, 1, 4, 16] C. [0, 1, 9, 16] D. [1, 4, 9, 16]

Answer: A

What is the expected effect of running the following code? class A: def __init__(self, v): self.__a = v + 1 a = A(0) print(a.__a) A) The code will raise an AttributeError exception B) The code will print 2 C) The code will print 0 D) The code will print 1

Answer: A

What is the expected result of the following code? from datetime import timedelta delta = timedelta(weeks = 1, days = 7, hours = 11) print(delta * 2) A) 28 days, 22:00:00 B) 2 weeks, 14 days, 22 hours C) 7 days, 22:00:00 D) The code will raise an exception

Answer: A

11. How many times will the loop run? i=2 while(i>0): i=i-1 A. 2 B. 3 C. 1 D. 0

Answer: A. 2

4. What is the output of the following code: print 9//2 A. 4 B. 4.5 C. 4.0 D. Error

Answer: A. 4

7. l = [ 4, 8, 9, 2.6, 5 ] is a type of which data type in python? A. List B. Tuple C. Set D. None of these

Answer: A. List ( lists in python are created with writing elements inside [] )

5. Which of the following declarations is incorrect? A. None Of the below B. _x = 2 C. __x = 3 D. __xyz__ = 5

Answer: A. None Of the below

10. A predefined Python variable that stores the current module name is called: A. __name__ B. __mod__ C. __modname__ D. __module__

Answer: A. __name__

12. When a module is imported, its contents: A. are executed once (implicitly) B. are ignored C. are executed as many times as they are imported D. may be executed (explicitly)

Answer: A. are executed once (implicitly)

1. Knowing that a function named fun() resides in a module named mod, choose the correct way to import it: A. from mod import fun B. import fun from mod C. from fun import mod D. import fun

Answer: A. from mod import fun

16. The digraph written as #! is used to: A. tell a Unix or Unix-like OS how to execute the contents of a Python file B. tell an MS Windows OS how to execute the contents of a Python file C. create a docstring D. make a particular module entity a private one

Answer: A. tell a Unix or Unix-like OS how to execute the contents of a Python file

10. Correct way to declare a variable x of float data type in python: A. x = 2.5 B. float x = 2.5 C. float(2.5) D. All of the above

Answer: A. x = 2.5

10:If the class's constructor is declared as below, which one of the assignments is valid? class Class: def __init__(self): pass A) object = Class B) object = Class() C) object = Class(self) D) object = Class(object)

Answer: B

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) A) it will raise an unhandled exception B) it will print bcac C) it will print acac D) it will print bcbc

Answer: B

12:What is the expected result of the following code? b = bytearray(3) print(b) A) 3 B) bytearray(b"\x00\x00\x00") C) bytearray(0, 0, 0) D) bytearray(b"3")

Answer: B

14:What is the expected output of the following code? import os os.mkdir("pictures") os.chdir("pictures") os.mkdir("thumbnails") os.chdir("thumbnails") os.mkdir("tmp") os.chdir("../") print(os.getcwd()) A) The path to the thumbnails directory B) The path to the pictures directory C) The path to the tmp directory D) The path to the root directory

Answer: B

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) A) it will print c B) it will print b C) it will print a D) it will raise an exception

Answer: B

2:A data structure described as LIFO is actually a: A) list B) stack C) heap D) tree

Answer: B

32. An operator able to check two values are not equal is coded as: A. =/= B. != C. <> D. not ==

Answer: B

34. How many stars (*) will the following snippet send to the console? A. zero B. the snippet will enter an infinite loop, printing one star per line C. one D. two

Answer: B

3:What keyword would you use to define an anonymous function? A) afun B) lambda C) def D) yield

Answer: B

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) A) 2 B) The code will raise an "AttributeError" exception C) 0 D) 1

Answer: B

Entering the try: block implies that: A. all of the instructions from this block will be executed B. some of the instructions from this block may not be executed C. the block will be omitted D. none of the instructions from this block will be executed

Answer: B. some of the instructions from this block may not be executed

The following statement: assert var == 0 A. is erroneous B. will stop the program when var != 0 C. has no effect D. will stop the program when var == 0

Answer: B. will stop the program when var != 0

1. Which of the following statements assigns the value 25 to the variable x in Python: A. x ← 25 B. x = 25 C. x := 25 D. int x = 25 E. x << 25

Answer: B. x = 25

10:What is the expected result of executing the following code? def fun(n): s = "+" for i in range(n): s += s yield s for x in fun(2): print(x, end="") A) It will print +++ B) It will print ++ C) It will print ++++++ D) It will print +

Answer: C

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

Answer: C

16:What is the expected result of the following code? import calendar c = calendar.Calendar() for weekday in c.iterweekdays(): print(weekday, end="") A) 1 2 3 4 5 6 7 B) Su Mo Tu We Th Fr C) 0 1 2 3 4 5 6 D) Mo Tu We Th Fr Sa Su

Answer: C

35. How many hashes (*) will the following snippet send to the console? A. nine B. zero C. three D. six

Answer: C

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)) A) it will print 1 B) it will print False C) it will print True D) it will raise an exception

Answer: C

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) A) it will print b B) it will print c C) it will print a D) it will raise an exception

Answer: C

How many element does the lst list contain? lst = [i for i in range(-1, -2)] A. two B. three C. zero D. one

Answer: C

If there are more than one except: branch after the try: clause, we can say that: A) exactly one except: block will be executed B) one or more except: blocks will be executed C) not more than one except: block will be executed D) none of the except: blocks will be executed

Answer: C

Knowing that a function named fun() resides in a module named mod, and was imported using the following statement: from mod import fun Choose the right way to invoke the fun() function: A) mod:fun() B) mod::fun() C) fun() D) mod.fun()

Answer: C

The following code: print(chr(ord("p") + 2)) will print: A) q B) s C) r D) t

Answer: C

The following statement: assert var != 0 A) is erroneous B) has no effect C) will stop the program when var == 0 D) will stop the program when var != 0

Answer: C

What is the excepted result of executing the following code? try: raise Exception(1, 2, 3) except Exception as e: print(len(e.args)) A) The code will raise an unhandled exception B) The code will print 2 C) The code will print 3 D) The code will print 1

Answer: C

What is the expected result of executing the following code? class A: pass class B(A): pass class C(B): pass print(issubclass(A, C)) A) The code will print True B) The code will print 1 C) The code will print False D) The code will raise an exception

Answer: C

What information can be read using the uname function provided by the os module? (Select two answers) import os os.mkdir("pictures") os.chdir("pictures") print(os.getcwd()) A) Last login date. B) Current path C) Operating system name D) Hardware identifier

Answer: C, D

The top-most Python exception is called: A. TopException B. Exception C. BaseException D. PythonException

Answer: C. BaseException

18. What will be the output of the following code? x = 12 for i in x: print(i) A. 12 B. 1 2 C. Error D. None of the above

Answer: C. Error (since you cannot loop through an integer)

12. What will be the output of the following Python code? for i in range(0,2,-1): print("Hello") A. Hello B. Hello Hello C. No Output D. Error

Answer: C. No Output

UTF-8 is: A. a Python version name B. the 9th version of the UTF standard C. a form of encoding Unicode code points D. a synonym for byte

Answer: C. a form of encoding Unicode code points

The following code: print(3 * 'abc' +'xyz') prints: A. xyzxyzxyzxyz B. abcabcxyzxyz C. abcabcabcxyz D. abcxyzxyzxyz

Answer: C. abcabcabcxyz

17. A function which returns a list of all entities available in a module is called: A. entities() B. content() C. dir() D. listmodule()

Answer: C. dir()

14. What keyword would you use to add an alternative condition to an if statement? A. else if B. elseif C. elif D. None of the above

Answer: C. elif

UNICODE is a standard: A. used by coders from universities B. honored by the whole universe C. like ASCII, but much more expansive D. for coding floating-point numbers

Answer: C. like ASCII, but much more expansive

6. The pip list command presents a list of: A. available pip commands B. outdated local package C. locally installed package D. all packages available at PyPI

Answer: C. locally installed package

15. Knowing that a function named fun() resides in a module named mod, and it has been imported using the following line: import mod Choose the way it can be invoked in your code: A. mod->fun() B. mod::fun() C. mod.fun() D. fun()

Answer: C. mod.fun()

19. Python programming language allows to use one loop inside another loop known as? A. switch B. foreach C. nested D. forall

Answer: C. nested

What is the expected output of the following code? try print("5"/0) except ArithmeticError: print("arith") except ZeroDivisionError: print("zero") except: print("some") A. zero B. 0 C. some D. arith

Answer: C. some

11:What is the meaning of the value represented by errno.EEXISTS? A) File doesn't exist B) Bad file number C) Permission denied D) File exists

Answer: D

2:What is the expected result of executing the code? def I(): s = "abcdef" for c in s[::2]: yield c for x in I(): print(x, end=" ") A) It will print abcdef B) It will print an empty line C) It will print bdf D) It will print ace

Answer: D

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) A. 1 B. 3 C. 2 D. 0

Answer: D

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) A. 1 1 B. 0 0 C. 1 0 D. 0 1

Answer: D

3:What will be the output of the following code? class A: A = 1 print(hasattr(A, 'A')) A) 0 B) False C) 1 D) True

Answer: D

5:Look at the code below: my_list = [1, 2, 3] # insert line of code here. print(foo) Which snippet would you insert in order for the program to output the following result (tuple): 1, 4, 27 A) foo = list(map(lambda x: x**x, my_list)) B) foo = tuple(map(lambda x: x*x, my_list)) C) foo = list(map(lambda x: x*x, my_list)) D) foo = tuple(map(lambda x: x**x, my_list))

Answer: D

6:What is the expected output of the following code? from datetime import date date_1 = date(1992, 1, 16) date_2 = date(1992, 2, 5) print(date_1 - date_2) A) 345 B) 345 days C) 345, 0:00:00 D) 345 days, 0:00:00

Answer: D

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

Answer: D

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))) A. 2None B. 1 C. the code will cause a runtime error D. 2

Answer: D

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)) A) it will print 1 B) it will print 2 C) it will raise as unhandled exception D) it will print 3

Answer: D

If you want to fill a byte array with data read in from a stream, which method you can use? A) The read() method B) The readbytes() method C) The readfrom() method D) The readinto() method

Answer: D

Look at the following code: numbers = [0, 2, 7, 9, 10] # Insert line of code here. print(list(foo)) Which line would you insert in order for the program to produce the expected output? [0, 4, 49, 81, 100] A) foo = lambda num: num ** 2, numbers B) foo = lambda num: num * 2, numbers C) foo = filter(lambda num: num ** 2, numbers) D) foo = map(lambda num : num ** 2, numbers)

Answer: D

What is the expected output of the following code? class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, "a")) A) 0 B) True C) 1 D) False

Answer: D

What output will appear after running the following snippet? A) The number of all the entities residing in the math module B) A string containing the fully qualified name of the module C) An error message D) A list of all the entities residing in the math module

Answer: D

Which pip command would you use to uninstall a previously install package? A) pip delete *packagename* B) pip -uninstall *packagename* C) pip -remove *packagename* D) pip uninstall *packagename*

Answer: D

2. What is the expected output of the following code? from random import randint for i in range(2): print(randint(1,2), end='') A. 12, or 21 B. there are millions of possible combinations, and the exact output cannot be predicted C. 12 D. 11, 12, 21, or 22

Answer: D. 11, 12, 21, or 22

8. If x=3.123, then int(x) will give ? A. 3.1 B. 0 C. 1 D. 3

Answer: D. 3

3. What will be the output of statement 2**2**2**2 A. 16 B. 256 C. 32768 D. 65536

Answer: D. 65536

9. Which of the following is not a data type in python? A. List B. Tuple C. Dictionary D. Book

Answer: D. Book

20. The continue statement can be used in? A. while loop B. for loop C. do-while D. Both A and B

Answer: D. Both A and B (continue statement can be used in both while loop and for loop in Python)

The following code: print('Mike' > " Mikey") prints: A. 0 B. 1 C. True D. False

Answer: D. False

17. What will be the output of the following code? x = "abcdef" i = "i" while i in x: print(i, end=" ") A. a b c d e f B. abcdef C. i i i i i..... D. No Output

Answer: D. No Output (because the while loop condition is never true since "i" is not in "abcdef")

3. During the first import of a module, Python deploys the pyc files in the directory called: A. mymodules B. __init__ C. hashbang D. __pycache__

Answer: D. __pycache__

6. Which of the following is a valid variable? A. var@ B. 32var C. in D. abc_x

Answer: D. abc_x

8. The following statement: from a.b import c causes the import of: A. entity a from module b from package c B. entity c from module a from package b C. entity b from module a from package c D. entity c from module b from package a

Answer: D. entity c from module b from package a

18. What is true about updating already installed Python packages? A. it can be done only by uninstalling and installing the package once again B. it's an automatic process which doesn't require any user attention C. it can be done by reinstalling the package using the reinstall command D. it's performed by the install command accompanied by the -U option

Answer: D. it's performed by the install command accompanied by the -U option

The unnamed except: block: A. must be the first one B. can be placed anywhere C. cannot be used if any named block has been used D. must be the last one

Answer: D. must be the last one

7. How to use pip to remove an installed package? A. pip --uninstall package B. pip remove package C. pip install --uninstall package D. pip uninstall package

Answer: D. pip uninstall package

ASCII is: A. a predefined Python variable name B. a standard Python module name C. a character name D. short for American Standard Code for Information Interchange

Answer: D. short for American Standard Code for Information Interchange

31. Which of the following snippets shows the correct way of handling multiple excepting in a single except clause? A. except TypeError, ValueError, ZeroDivisinError: # Some code. B. except: (TypeError, ValueError, ZeroDivisinError) # Some code. C. except TypeError, ValueError, ZeroDivisinError # Some code. D. except: TypeError, ValueError, ZeroDivisinError # Some code. E. except: (TypeError, ValueError, ZeroDivisinError): # Some code. F. except (TypeError, ValueError, ZeroDivisinError) # Some code.

Answer: E

Assuming that the following three files a.py, and c.py reside in the same directory, what will be the output produced after running the c.py file? python # file a.py print("a", end="") # file b.py import a print("b", end="") # file c.py print("c", end="") import a import b a. cab b. cab c. abc d. bac

Answer: a

Look at the following code: python numbers = [i*i for i in range(5)] # Insert line of code here. print(foo) Which line would you insert in order for the program to produce the expected output? python [1, 9] a. foo = list(filter(lambda x: x % 2, numbers)) b. foo = list(filter(lambda x: x / 2, numbers)) c. foo = list(map(lambda x: x % 2, numbers)) d. foo = list(map(lambda x: x // 2, numbers))

Answer: a

What is the expected result of executing the following code? python def o(p): def q(): return "*" * p return q r = o(1) s = o(2) print(r() + s()) a. The code will print *** b. The code will print **** c. The code will print * d. The code will print **

Answer: a

What is the expected result of the following snippet? python try: raise Exception except: print("c") except BaseException: print("a") except Exception: print("b") a. The code will cause a syntax error b. 1 c. b d. a

Answer: a

2. What is the expected output of the following snippet? print(len([i for i in range(0, -2)])) a) 0 b) 1 c) 2 d) 3

Answer: a) 0

18. What is the expected output of the following snippet? d = ("one": 1, "three": 3, "two":2) for k in sorted(d.values()): print(k, end=" ") a) 1 2 3 b) 2 3 1 c) 3 1 2 d) 3 2 1

Answer: a) 1 2 3

37. What is the expected output of the following piece of code? x, y, z = 3, 2, 1 z, y, x = x, y, z print(x, y, z) a) 1 2 3 b) 1 2 2 c) 2 1 3 d) 3 2 1

Answer: a) 1 2 3

41. What is the expected output of the following code? from datetime import timedelta delta = timedelta(weeks = 1, days = 7, hours = 11) print(delta) a) 14 days, 11:00:00 b) 1 week, 7 days, 11 hours c) 2 weeks, 11:00:00 d) 7 days, 11:00:00

Answer: a) 14 days, 11:00:00

49. What is the expected output of the following code? t = (1, ) t = t[0] + t[0] print(t) a) 2 b) (1, ) c) (1, 1) d) 1

Answer: a) 2

15. Which operator would you use to check whether two values are equal? a) == b) === c) = d) is

Answer: a) ==

6. What is the expected output of the following snippet? class A: def __init__(self,name): self.name = name a = A("class") print(a) a) A string ending with a long hexadecimal number b) class c) name d) A number

Answer: a) A string ending with a long hexadecimal number

19. Select the true statements. (Select two answers) a) If a class contains the __init__ method, it cannot return any value b) If a class contains the __init__ method, it can return a value c) The first parameter of a class method does not have to be named self d) The first parameter of a class method must be named self

Answer: a) If a class contains the __init__ method, it cannot return any value, c) The first parameter of a class method does not have to be named self

36. What is true about the following code snippet? def fun(par2, par1): return par2 + par1 print(fun(par2 = 1, 2)) a) The code is erroneous b) The code will output 1 c) The code will output 2 d) The code will output 3

Answer: a) The code is erroneous

14. Which is the expected behavior of the following snippet? def fun(x): return 1 if x % 2 != else 2 print(fun(fun(1))) a) The code will cause a runtime error b) The program will output 1 c) The program will output 2 d) The program will output None

Answer: a) The code will cause a runtime error

35. What is the expected behavior of the following snippet? try: raise Exception except: print("c") except BaseException: print("a") except Exception: print("b") a) The code will cause an error b) The code will output a c) The code will output b d) The code will output c

Answer: a) The code will cause an error

43. What is the expected behavior of the following snippet? my_string = "abcdef" def fun(s): del s[2] return s print(fun(my_string)) a) The program will cause an error b) The program will output abdef c) The program will output acdef d) The program will output abcef

Answer: a) The program will cause an error

31. A package directory/folder may contain a file intended to initialize the package. What is its name? a) __init__.py b) __init.py__ c) __init__. d) init.py

Answer: a) __init__.py

28. What is the expected output of the following code, located in the file module.py? print(__name__) a) __main__ b) __module.py__ c) main d) modle.py

Answer: a) __main__

10. The meaning of a Keyword argument is determined by its: a) both name and value assigned to it b) connection with existing variables c) position within the argument list d) value only

Answer: a) both name and value assigned to it

23. Which of the following functions provided by the os module are available in both Windows and Unix? (Select two answers) a) chdir() b) getgid() c) getgroups() d) mkdir()

Answer: a) chdir(), d) mkdir()

40. If the class constructor is declared as below: class Class: def __init__(self): pass which one of the assignments is valid? a) object = Class() b) object = Class(1) c) object = Class(1, 2) d) object = Class(None)

Answer: a) object = Class()

3. How many stars * will the following snippet send to the console? i = 4 while i > 0 : i -= 2 print("*") if i == 2: break else: print("*") a) one b) The snippet will enter an infinite loop, constantly printing one * per line c) two d) zero

Answer: a) one

26. Which of the following sentences is true about the snippet below? str_1 = "string" str_2 = str_1[:] a) str_1 and str_2 are different (but equal) strings b) str_1 and str_2 are different names of the same string c) str_1 is longer than str_2 d) str_2 is longer than str_1

Answer: a) str_1 and str_2 are different (but equal) strings

32. If there is a finally: branch inside the try: block, we can say that: a) the finally: branch will always be executed b) the finally: branch won't be executed if any of the except: branch is executed c) the finally: branch won't be executed if no exception is raised d) the finally: branch will be executed when there is no else: branch

Answer: a) the finally: branch will always be executed

34. If you want to write a byte array's content to a stream, which method can you use? a) write() b) writebytearray() c) writefrom() d) writeto()

Answer: a) write()

52. What is the expected behavior of the following piece of code? python d = {1: 0, 2: 1, 3: 2, 0: 1} x = 0 for y in range(len(d)): x = d[x] print(x) a. The code will output 0 b. The code will output 1 c. The code will cause a runtime error d. The code will output 2

Answer: a. The code will output 0

60. How many empty lines will the following snippet send to the console? python my_list = [[c for c in range(r)] for r in range(3)] for element in my_list: if len(element) < 2: print() a. two b. three c. zero d. one

Answer: a. two

Assuming that the​ open() invocation has gone successfully, the following snippet: python for x in open("file", "rt")): print(x) will: a. read the file character by character b. read the file line by line c. read the whole file at once d. cause an exception

Answer: b

What is the expected result of executing the following code? python class A: def __init__(self): pass a = A(1) print(hasattr(a, "A")) a. The code will print 1 b. The code will raise an exception c. The code will print False d. The code will print True

Answer: b

48. What is the expected output of the following code? def fun(n): s = " " for i in range(n): s += "*" yield s for x in fun(3): print(x, end="") a) **** b) ****** c) 2*** d) *

Answer: b) ******

8. What is the expected output of the following code? from datetime import datetime datetime = datetime(2019, 11, 27, 11, 27, 22) print(datetime.strftime("%Y/%m/%d %H:%M:%S")) a) 19/11/27 11:27:22 b) 2019/11/27 11:27:22 c) 2019/November/27 11:27:22 d) 2019/Nov/27 11:27:22

Answer: b) 2019/11/27 11:27:22

42. What is the expected output of the following piece of code if the user enters two lines containing <code>1</code> and <code>2</code> respectively? y = input() x = input() print(x + y) a) 2 b) 21 c) 12 d) 3

Answer: b) 21

38. What is the expected output of the following snippet? d = {} d["2"] = [1, 2] d["1"] = [3, 4] for x in d.keys(): print(d[x][1], end="") a) 13 b) 24 c) 31 d) 42

Answer: b) 24

24. What is the expected output of the following piece of code? v = 1 + 1 // 2 + 1 / 2 + 2 a) 3 b) 3.5 c) 4 d) 4.0

Answer: b) 3.5

47. What is the expected output of the following code? import calendar c = calendar.Calendar(calendar.SUNDAY) for weekday in c.iterweekdays(): print(weekday, end=" ") a) 7 1 2 3 4 5 6 b) 6 0 1 2 3 4 5 c) Su Mo Tu We Th Fr Sa d) Su

Answer: b) 6 0 1 2 3 4 5

5. What is the expected output of the following snippet? class X: pass class Y(X): pass class Z(Y): pass x = X() z = Z() print(isinstance(x, z), isinstance(z, X)) a) False False b) False True c) True False d) True True

Answer: b) False True

20. Select the true statements. (Select two answers) a) PyPI is one of many existing Python repository b) PyPI is short for Python Package Index c) PyPI is short for Python Package Installer d) PyPI is the only existing Python repository

Answer: b) PyPI is short for Python Package Index, c) PyPI is short for Python Package Installer

17. What can you do if you want to tell your module users that a particular variable should not be accessed directly? a) Build its name with lowercase letters only b) Start its name with __or__ c) Start its name with a capital letter d) Use its number instead of its name

Answer: b) Start its name with __or__

22. What is the expected effect of running the following code? class A: def __init__(self, v): self._a = v + 1 a = A(0) print(a._a) a) The code will output 0 b) The code will output 1 c) The code will output 2 d) The code will raise an AttributeError exception

Answer: b) The code will output 1

44. What is true about the following snippet? def fun(d, k, v): d[k] = v my_dictionary = {} print(fun(my_dictionary, "1", "v")) a) The code is erroneous b) The code will output None c) The code will output v d) The code will output 1

Answer: b) The code will output None

50. What is the expected result of executing the following code? class A: def a(self): print("a") class B: def a(self): print("b") class C(A, B): def c(self): self.a() o = C() o.c() a) The code will print c b) The code will print a c) The code will raise an exception d) The code will print b

Answer: b) The code will print a

16. What is the name of the directory/folder created by Python used to store pyc files? a) __cache__ b) __pycache__ c) __pyc__ d) __pycfiles

Answer: b) __pycache__

25. If s is a stream opened in read mode, the following line: q = s.readlines() will assign q as : a) dictionary b) list c) string d) tuple

Answer: b) list

29. What is the expected output of the following code? def a(x): def b(): return x + x return b x = a("x) y = a("") print(x() + y()) a) x b) xx c) xxxx d) xxxxxx

Answer: b) xx

Which of the following commands would you use to check pip"s version? (Select two answers) a. pip version b. pip --version c. pip-version d. pip3 --version

Answer: b, d

58. What is the expected behavior of the following code? python x = "\" print(len(x)) a. The code will output 3 b. The code will cause an error c. The code will output a2 d. The code will output 1

Answer: b. The code will cause an error

55. Which line properly invokes the function defined as below? python def fun(a, b, c=0): # function body a. fun(b=0, b=0) b. fun(a=1, b=0, c=0) c. fun(1, c=2) d. fun(0)

Answer: b. fun(a=1, b=0, c=0)

53. What pip operation would you use to check what Python packages have been installed so far? a. show b. list c. help d. dir

Answer: b. list

If the class constructor is declared in the following way: python class Class: def __init__(self, vla = 0): pass which one of the assignments is invalid? a. object = Class(1) b. object = Class(None) c. object = Class(1, 2) d. object = Class()

Answer: c

The following line of code: python for line in open("text.txt", "rt"): a. in invalid because open returns nothing b. is invalid because open returns a non-iterable object c. is invalid because open returns an iterable object d. may be valid if line is a list

Answer: c

What will be the output of the following code, located in the p.py file? python print(__name__) a. main b. p.py c. __main__ d. __p.py__

Answer: c

21. What is the expected output of the following snippet? t = (1, 2, 3, 4) t = t[-2:-1] t = t[-1] print(t) a) (3) b) (3,) c) 3 d) 33

Answer: c) 3

7. What is the expected result of executing the following code? class A: pass class B: pass class C(A, B): pass print(issubclass(C, A) and issubclass(C, B)) a) The code will print False b) The code will print an empty line c) The code will print True d) The code will raise an exception

Answer: c) The code will print True

1. What is the expected output of the following snippet? a = True b = False a = a or b b = a and b a = a or b print(a, b) a) False False b) False True c) True False d) True True

Answer: c) True False

9. What is the expected output of the following code? my_string_1 = "Bond" my_string_2 = "James Bond" print(my_string_1.isalpha(), my_string_2.isalpha()) a) False False b) False True c) True False d) True True

Answer: c) True False

39. What is the expected output of the following snippet? try: raise Exception except BaseException: print("a", end="") else: print("b", end="") finally: print("c") a) a b) ab c) ac d) bc

Answer: c) ac

54. What is true about the following line of code? python print(len((1, ))) a. The code will output 0 b. The code is erroneous c. The code will output 1 d. The code will output 2

Answer: c. The code will output 1

57. What is true about the following piece of code? python print("a", "b", "c", sep=" " ") a. The code is erroneous b. The code will output abc c. The code will output a"b"c d. The code will output a b c

Answer: c. The code will output a"b"c

If a is a stream opened in read mod, the following line: python q = s.read(1) will read: a. one line from the stream b. one kilobyte from the stream c. one buffer from the stream d. one character from the stream

Answer: d

The following code: python x = " \\" print(len(x)) a. will print 1 b. will print 3 c. will print 2 d. will cause an error

Answer: d

The sys.stderr stream is normally associated with: a. the keyboard b. the printer c. a null device d. the screen

Answer: d

What is the expected result of the following code? python def my_fun(n): s = "+" for i in range(n): s += s yield s for x in my_fun(2): print(x, end="") a. The code will print + b. The code will print +++ c. The code will print ++ d. The code will print ++++++

Answer: d

What is the expected result of the following code? python import os os.mkdir("pictures") os.chdir("pictures") print(os.getcwd()) a. The code will print the owner of the created directory b. The code will print the content of the created directory c. The code will print the name of the created directory d. The code will print the path to the created directory

Answer: d

13. What is PEP 8? a) A document that provides coding conventions and style guide for the C code computing the C implementation of Python b) A document that describes an extension to Python's import mechanism which improves sharing of Python source code files c) A document that describes the development and release schedule for Python versions d) A document that provides coding conventions and style guide for Python code

Answer: d) A document that provides coding conventions and style guide for Python code

12. The Exception class contains a property named args - what is it? a) A dictionary b) A list c) A string d) A tuple

Answer: d) A tuple

30. What is the expected behavior of the following piece of code? x = 16 while x > 0: print("*", end="") x //= 2 a) The code will error an infinite loop b) The code will output * c) The code will output *** d) The code will output *****

Answer: d) The code will output *****

46. What is the expected behavior of the following code? x = """ """ print(len(x)) a) The code will output 2 b) The code will output 3 c) The code will cause an error d) The code will output 1

Answer: d) The code will output 1

27. What is the expected result of executing the following code? class A: def __init__(self): pass def f(self): return 1 def g(): return self.f() a = A() print(a.g()) a) The code will output 0 b) The code will output 1 c) The code will output True d) The code will raise an exception

Answer: d) The code will raise an exception

11. Knowing that the function named m, and the code contains the following import statement: from f import m Choose the right way to invoke the function: a) f() b) mod:f() c) mod.f() d) The function cannot be invoked because the import statement is invalid

Answer: d) The function cannot be invoked because the import statement is invalid

4. What is the sys.stdout stream normally associated with? a) A null device b) The keyboard c) The printer d) The screen

Answer: d) The screen

33. What value will be assigned to the x variable? z = 2 y = 1 x = y < z or z > y and y > z or z < y a) 0 b) 1 c) False d) True

Answer: d) True

45. What is the expected output of the following code? class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, "A")) a) False b) 1 c) 0 d) True

Answer: d) True

59. What is the expected output of the following code? python class A: A = 1 def __init__(self, v=2): self.v = v + A.A A.A += 1 def set(self, v): self.v += v A.A += 1 return a = A() a.set(2) print(a.v) a. 7 b. 1 c. 3 d. 5

Answer: d. 5

51. What is the expected behavior of the following code snippet? python my_list = [1, 2, 3, 4] my_list = list(map(lambda x: 2*x, my_list)) print(my_list) a. The code will cause a runtime error b. The code will output 1 2 3 4 c. the code will output 10 d. The code will output 2 4 6 8

Answer: d. The code will output 2 4 6 8

The fact that tuples belong to sequence types means that: they can be indexed and sliced like lists they can be extended using the .append() method they can be modified using the del instruction they are actually lists

Answer: they can be indexed and sliced like lists

Which of the following are examples of Python built-in concrete exceptions?(Select two answers) A. ArithemticError B. IndexError C. BaseException D. ImportError

B. IndexError D. ImportError

What is true compilation? (Select two answers) A. Both you and user must have the compiler to run your code B. The code is converted directly into machine code executable by the processor C. It tends to be faster than interpretation D. It tends to be than interpretation

B. The code is converted directly into machine code executable by the processor C. It tends to be faster than interpretation

Take a look at the snippet, and choose the true statements: (Select two answer) nums = [1, 2, 3] vals = nums del vals[1:2] A. nums is longer than vals B. nums and vals are of the same length C. nums and vals refer to the same list D. nums is replicated and assigned to vals

B. nums and vals are of the same length C. nums and vals refer to the same list

13. Choose the true statements. (Select two answers) A. The version function from the platform module returns a string with your Python version B. The processor function from the platform module returns an integer with the number of processes currently running in your OS C. The version function from the platform module returns a string with your OS version D. The system function from the platform module returns a string with your OS name

C. The version function from the platform module returns a string with your OS version, D. The system function from the platform module returns a string with your OS name

How many stars (*) will the following snippet send to the console? i = 0 while i <= 3 : i += 2 print("*") A. three B. zero C. one D. two

D. two

What is the output of the following snippet? t = [[3-i for i in range(3)] for j in range(3)] s = 0 for i in range(3): s += t[i][i] print(s) A. 4 B. 7 C. 0 D. 2 E. 6

E. 6

What is the output of the following snippet? def ant(): print(var + 1, end ='') var = 1 any() print(var) -12 -22 -11 -21

21

What do you call a file containing a program written in a high-level programming language? A. A machine file B. A code file C. A target file D. A source file

A source file

The result of the following division: 1 / 1 is equal to: A. 1.0 B. is equal to 1 C. cannot be evaluated D. cannot be predicted

A. 1.0

What is the output of the following snippet if the user enters two lines containing 3 and 6 respectively? x = input() y = int(input()) print(x * y) A. 333333 B. 36 C. 18 D. 666

A. 333333

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) x = x / y y = y / x print(y) A. 8.0 B. the code will cause a runtime error C. 4.0 D. 2.0

A. 8.0

11. What is true about the pip search command? (Select three answers) A. all its searches are limited to locally installed packages B. it needs working internet connection to work C. it searches through all PyPI packages D. it searches through package names only

A. all its searches are limited to locally installed packages, B. it needs working internet connection to work, C. it searches through all PyPI packages

14. What is true about the pip install command? (Select two answers) A. it allows the user to install a specific version of the package B. it installs a package system-wide only when the --system option is specified C. it installs a package per user only when the --user option is specified D. it always installs the newest package version and it cannot be changed

A. it allows the user to install a specific version of the package, C. it installs a package per user only when the --user option is specified

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) x = x // y y = y // x print(y) A. the code will cause a runtime error B. 2.0 C. 8.0 D. 4.0

A. the code will cause a runtime error

What is the output of the following snippet? y = 2 + 3 * 5. print(Y) A. the snippet will cause an execution error B. 25. C. 17 D. 17.0

A. the snippet will cause an execution error

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="") A. 21 B. (2,1) C. 12 D. (1,2)

Answer: A

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) A.__init__(self) B) __init__() C) A.__init__() D) A.__init__(1)

Answer: A

8:What is the expected result of executing the following code? def o(p): def q(): return "*" * p return q r = o(1) s = o(2) print(r() + s()) A) it will print *** B) it will print *** C) it will print ** D) it will print *

Answer: A

9:Look at the code below: my_tuple = (0, 1, 2, 3, 4, 5, 6) # Insert line of code here. print(foo) Which snippet would you insert in order for the program to output the following result (list): [2, 3, 4, 5, 6] A) foo = list(filter(lambda x: x-0 and x-1, my_tuple)) B) foo - list(filter(lambda x: x==0 and x==1, my_tuple)) C) foo = tuple(filter(lambda x: x>1, my_tuple)) D) foo = tuple(filter(lambda x: x-0 and x-1, my_tuple))

Answer: A

Look at the code below: import random # # Insert lines of code here. # print(a, b, c) Which lines of code would you insert so that it is possible for the program to output the following result: 6 82 0 A) a = random.randint(0, 100) b = random.randrange(10, 100, 3) c = random.choice((0, 100, 3)) B) a = random.choice((0, 100, 3)) b = random.randrange(10, 100, 3) c = random.randint(0, 100) C) a = random.randrange(10, 100, 3) b = random.randint(0, 100) c = random.choice((0, 100, 3)) D) a = random.randint(0, 100) b = random.choice((0, 100, 3)) c = random.randrange(10, 100, 3)

Answer: A

The following code: print(float("1.3")) A) will print 1.3 B) will print 13 C) will print 1,3 D) will raise a ValueError exception

Answer: A

1:Which of the following open modes allow you to perform read operations? (Select two answers) A) r B) a C) r+ D) w

Answer: A, C

7:Which program will produce the following output: Mo Tu We Th Fr Sa Su A) import calendar print(calendar.weekheader(3)) B) import calendar print(calendar.weekheader(2)) C) import calendar print(calendar.week) D) import calendar print(calendar.weekheader())

Answer: B

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) A) 2 B) 3 C) 0 D) 1

Answer: B

The following code: x = "\\\\" print(len(x)) A) will print 1 B) will print 2 C) will cause an error D) will print 3

Answer: B

What is the excepted result of the following snippet? try: raise Exception except BaseException: print("a") except Exception: print("b") except: print("c") A) b B) a C) An error message D) 1

Answer: B

What is the expected result of executing the following code? class I: def __init__(self): self.s = "abc" self.i = 0 def __init__(self): return self def __next__(self): if self.i == len(self.s): raise StopIteration v = self.s[self.i] self.i += 1 return v for x in I(): print(x, end="") A) The code will print 210 B) The code will print abc C) The code will print 012 D) The code will print cba

Answer: B

What is the expected result of the following code? import calendar calendar.setfirstweekday(calendar.SUNDAY) print(calendar.weekheader(3)) A) Su Mo Tu We Th We Fr Sa B) Sun Mon Tue Wed Thu Fri Sat C) Tu D) Tue

Answer: B

5. What is the expected value of the result variable after the following code is executed? import math result = math.e != math.pow(2, 4) print(int(result)) A. 0 B. 1 C. False D. True

Answer: B. 1

The following code: print(ord('c') - ord('a')) prints: A. 0 B. 2 C. 3 D. 1

Answer: B. 2

9. The pyc file contains: A. a Python interpreter B. compiled Python code C. Python source code D. a Python compiler

Answer: B. compiled Python code

16. Which of the following is a valid for loop in Python? A. for(i=0; i < n; i++) B. for i in range(0,5): C. for i in range(0,5) D. for i in range(5)

Answer: B. for i in range(0,5):

13. Which one of the following is a valid Python if statement: A. if a>=2 : B. if (a >= 2) C. if (a => 22) D. if a >= 22

Answer: B. if (a >= 2)

15. Which statement will check if a is equal to b? A. if a = b: B. if a == b: C. if a === c: D. if a == b

Answer: B. if a == b:

2. Which one of the following is the correct way of declaring and initializing a variable, x with the value 7? A. int x x=7 B. int x=7 C. x=7 D. declare x=7

Answer: B. int x=7

The following code: print (float("1, 3" )) A. prints 1, 3 B. raises a ValueError exception C. prints 1.3 D. prints 13

Answer: B. raises a ValueError exception

4. A list of package's dependencies can be obtained from pip using its command named: A. deps B. show C. dir D. list

Answer: B. show

What is the expected 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() A) The code will print c B) The code will raise an exception C) The code will print b D) The code will print a

Answer: C

What is the expected result of the following code? from datetime import datetime datetime_1 = datetime(2019, 11, 27, 11, 27, 22) datetime_2 = datetime(2019, 11, 27, 0, 0, 0) print(datetime_1 - datetime_2) A) 0 days B) 0 days, 11:27:22 C) 11:27:22 D) 11 hours, 27 minutes, 22 seconds

Answer: C

4:Select the true statements. (Select two answers) A) The lambda function can accept a maximum of two arguments B) The lambda function can evaluate multiple expressions C) The lambda function can evaluate only one expression D) The lambda function can accept any number of arguments

Answer: C, D

15:What is the expected output of the following code? import os os.mkdir("thumbnails") os.chdir("thumbnails") sizes = ["small", "medium", "large"] for size in sizes: os.mkdir(size) print(os.listdir()) A) [".", "..", "large", "small", "medium"] B) [] C) [".", "large", "small", "medium"] D) ["large", "small", "medium"]

Answer: D

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) A) it will raise an exception B) it will print 2 C) it will print an empty line D) it will print 1

Answer: D

The compiled Python bytecode is stored in files which have their names ending with: A) py B) pyb C) pc D) pyc

Answer: D

What is the expected output of the following code? class A: def __init__(self, v=2): self.v = v def set(self, v=1): self.v += v return self.v a = A() b = a b.set() print(a.v) A) 1 B) 0 C) 2 D) 3

Answer: D

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) A. two B. ('one', 'two', 'three') C. three D. one

Answer: D

What is the output of the following snippet? def fun(x): x += 1 return x x = 2 x = fun(x + 1) print(x) A. 3 B. 5 C. the code is erroneous D. 4

Answer: D

The following code: x = '' ' print(len(x)) prints: A. 3 B. 2 C. 20 D. 1

Answer: D. 1

The following code: print(chr(ord('z') - 2)) prints: A. z B. y C. a D. x

Answer: D. x

56. What is the expected behavior of the following code? python import os os.makedirs("pictures/thumbnails") os.rmdir("pictures") a. The code will delete both the pictures and thumbnails directories b. The code will delete the pictures directory only c. The code will raise an error d. the code will delete the thumbnails directory only

Answer: c. The code will raise an error

A built-in function is a function which: is hidden from programmers has been placed within your code by another programmer has to be imported before use comes with Python, ans is an integer part of Python

Answer: comes with Python, ans is an integer part of Python

The following statement: python from a.b import c causes the import of: a. entity a from module b from package c b. entity b from module a from package c c. entity c from module a from package b d. entity c from module b from package a

Answer: d

Left-sided binding determines that the result of the following expression: 1 // 2 * 3 is equal to: A. 0.0 B. 0 C. 4.5 D. 0.166666666666666666

B. 0

How many elements does the my_list list contain? my_list = [i for i in range(-1, 2)] A. Two B. Three C. Four D. One

B. Three

What is the expected behavior of the following program? print("Hello!") A. The program will output ("Hello!") to the screen B. The program will generate an error message on the screen C. The program will output Hello! to the screen D. The program will output "Hello!" to the screen

The program will output Hello! to the screen

Which of the following sentences are true? (Select two answers) nums = [1, 2, 3] vals = nums[-1:-2] - nums and vals are two different lists - vals is longer than nums - nums and vals are of the same length - nums is longer than vals

nums and vals are two different lists, nums is longer than vals

The second assignment: vals = [0, 1, 2] vals[0], vals[2] = vals[2], vals[0] - doesn't change the list - reverses the list - shortens the list - extends the list

reverses the list

Which of the following statements are true? (Select two answers) A. Python is a good choice for creating and executing tests for applications B. Python 3 is backwards compatible with Python 2 C. Python is a good choice for low-level programming e.g., when you want to implement an effective driver D. Python is free, open-source, and multiplatform

A. Python is a good choice for creating and executing tests for applications, D. Python is free, open-source, and multiplatform

What is the expected behavior of the following program? print("Goodbye!") A. The program will output Goodbye! to the screen B. The program will generate an error message on the screen C. The program will output("Goodbye!") D. The program will output "Goodbye!" to the screen

A. The program will output Goodbye! to the screen

4. The meaning of a positional argument is determined by: A. its position within the argument list B. its connection with existing variables C. its value D. the argument's name specified along with its value

Answer: A

What is the expected behavior of the following program? foo = (1, 2, 3) foo.index(0) A. The program will cause a ValueError exception. B. The program will output 1 to the screen. C. The program will cause a SyntaxError exception. D. The program will cause a TypeError exception. E. The program will cause an AttributeError exception.

Answer: A

What is the output of the following snippet? def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3)) A. 6 B. the code is erroneous C. 1 D. 3

Answer: A

What is the output of the following snippet? def fun(inp =2, out =3): return inp * out print(fun(out =2)) A. 4 B. 6 C. 2 D. the snippet is erroneous and will cause SyntaxError

Answer: A

What is the output of the following snippet? def fun(x, y, x): return x + 2 * y + 3 * z print(fun(0, z=1, y=3)) A. 9 B. 0 C. 3 D. the snippet is erroneous

Answer: A

Select the true statements about the try-exception block in relation to the following example. (Select two answers.) try: # Some code is here... except: # some code is here... A. if you suspect that a snippet may raise an exception, you should place it in the try block B. The code that follows the try statement will be executed if the code in the except clause runs into an error. C. The code that follows the except statement will be executed if the code in the try clause runs into an error. D. If there is a syntax error in code located in the try block, the except branch will not handle it, and a SyntaxError exception will be raised instead.

Answer: A and C

Which of the following statement are true? (Select two answers) A. The None value can be assigned to variables B. The None value cannot be used outside functions C. The None value can be used as an argument of arithmetic operators D. The None value can be compared with variables

Answer: A and D

Which of the following statements are true about a function defined in the following way? def function(x=0): return x A. The function may be invoked with exactly one argument B. The function may be invoked without any argument C. The function must be invoked with exactly one argument D. The function must be invoked without any argument

Answer: A and D

10. Which of the following sentences are true about the code? (Select two answers) nums = [1, 2, 3] vals = nums A. nums and vals are different names of the same list B. vals is longer than nums C. nums and vals are different lists D. nums has the same length as vals

Answer: A, D

What is the output of the following snippet? def func(a, b): return a ** a print(func(2)) A. is erroneous B. will output 2 C. will output 4 D. will return None

Answer: A. is erroneous

2. Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction: my_tuple[1] = my_tuple[1] + my_tuple[0] A. may be illegal if the tuple contains strings B. is illegal C. can be executed if and only if the tuple contains at least two elements D. is full correct

Answer: B

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...") A. The program will cause a ValueError exception and output the following message Too bad... B. The program will cause a SyntaxError exception C. The program will cause a ValueError exception and output a default error message. D. The program will raise an exception handle by the first except block. E. The program will cause a ZeroDivisionError exception and output the following message: Too bad... F. The program will cause a ZeroDivisionError exception and output a default error message.

Answer: B

5. What will happen when you attempt to run the following code? print(Hello, World) A. The code will raise the AttributeError exception. B. The code will raise the systemError exception. C. The code will raise the ValueError exception. D. The code will print Hello World to the console. E. The code will raise the TyepError exception.

Answer: B

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)) A. will output 16 B. will create a runtime error C. will output 4 D. will output 2

Answer: B

Assuming that my_tuple is a correctly created tuple, the fact that tuples are immutable means that the following instruction: my_tuple[1] = my_tuple[1] + my_tuple[0] A. can be executed if and only if the tuple contains at least two elements B. is illegal C. may be illegal if the tuple contains string D. is fully correct

Answer: B

The result of the following division: 1 // 2 A. is equal to 0.5 B. is equal to 0 C. is equal to 0.0 D. cannot be predicted

Answer: B

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)) A. 4.0 B. 2.0 C. 0.0 D. 1.0

Answer: B

What is the output of the following snippet? tup = (1, 2, 4, 8) tup = tup[-2:-1] tup = tup[-1] print(tup) A. 44 B. 4 C. (4) D. (4,)

Answer: B

What is the output of the following snippet? def fun(x): global y y = x * x return y fun(2) print(y) A. the code will cause a runtime error B. 4 C. None D. 2

Answer: B

What is the output of the following snippet? def func_1(a): return a ** a def func_2(a): return func_1(a) * func_1(a) print(func_2(2)) A. will output 2 B. will output 16 C. will output 4 D. is erroneous

Answer: B

Which one if the following lines properly starts a parameterless function definition? A. def fun: B. def fun(): C. function fun(): D. fun function():

Answer: B

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. A. fun() B. fun(0, 1, 2) C. fun(b=0, a=0) D. fun(b=1)

Answer: B, C

Which of the following variable names are illegal and will cause the SystemError exception? (Select two answers) A. print B. in C. for D. In

Answer: B, C

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) A. 2 1 2 B. 1 2 2 C. 1 1 2 D. 1 2 1

Answer: C

What is the output of the following piece of the code if the user enters two lines containing 3 and 6 respectively? y = input() x = input() print(x + y) A. 36 B. 3 C. 63 D. 6

Answer: C

What is the output of the following snippet? def fun(inp=2, out=3): return inp * out print(fn(out =2)) A. 2 B. 6 C. 4 D. the snippet is erroneous

Answer: C. 4

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) A. [1, 2, 2, 2] B. [1, 2, 1, 2] C. [2, 1, 1, 2] D. [1, 1, 1, 2]

Answer: D

13. What is the output of the following piece of code? x = 1 // 5 + 1 / 5 print(x) A. 0.0 B. 0 C. 0.4 D. 0.2

Answer: D

27. Take a look at the snippet and choose the true statement: nums = [1, 2, 3] vals = nums del vals[:] A. the snippet will cause a runtime error B. vals is longer than nums C. nums is longer than vals D. nums and vals have the same length

Answer: D

29. What is the output of the following snippet? dd = {"1": "0", "0": "1"} for x in dd.vals(): print(x, end="") A. 0 1 B. 1 0 C. 0 0 D. the code is erroneous(the dict object has no vals() method)

Answer: D

6. The following snippet: def func(a, b): reeturn b ** a print(func(b=2, 2)) A. will output 4 B. will output None C. will output 2 D. is erroneous

Answer: D

9. What is the output of the following piece of code? print("a", "b", "c", sep="sep") A. a b c B. abc C. asepbsepcsep D. asepbsepc

Answer: D

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)) A. 1 B. 2 C. the snippet will cause a runtime error D. 0

Answer: D

What is the output of the following snippet? dictionary = {'one': 'two', 'three': 'one', 'two': 'three'} v = dictionary['one'] for k in range(len(dictionary)): v = dictionary[v] print(v) A. three B. one C. ('one', 'two', 'three') D. two

Answer: D

What is the output of the following snippet? my_list = ['Mary', 'had', 'a', 'little', 'lamb'] def my_list(my_list): del my_list[3] my_list[3] = 'ram' print(my_list(my_list)) A. ['Mary', 'had', 'a' ,'lamb'] B. ['Mary', 'had', 'a' ,'ram'] C. ['Mary', 'had', 'a' ,'little', 'lamb'] D. no output, the snippet is erroneous

Answer: D

What is the output of the following snippet? tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup) A. the snippet is erroneous B. (12) C. (2, ) D. 2

Answer: D

What value will be assigned to the x variable? z = 0 y = 0 x = y < z and z > y or y > z and z < y A. False B. 0 C. 1 D. True

Answer: D

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!") A. Very bad input... B. Very very bad input... C. Bad input... D. Booo! E. 0.0 F. 1.0

Answer: E

What is the output of the following code? try: value = input("Enter a value: ") print(value/value) except: print("Bad input...") except ZeroDivisionError: print("Very bad input...") except TypeError: print("Very very bad input...") except: print("Booo!") -Booo! -Bad input... -Very very bad input... -Very bad input...

Answer: Very very bad input...

After execution of the following snippet, the sum of the all vals elements will equal to: vals = [0, 1, 2] vals.insert(0, 1) del vals[1] A. 3 B. 4 C. 2 D. 5

B. 4

What do you call a command-line interpreter which lets you interact with your OS and execute Python commands and scripts? A. An editor B. A console C. A compiler D. Jython

B. A console

What are the four fundamental elements that make a language? A. An alphabet, morphology, phonetics, and semantics B. An alphabet, a lexis, a syntax, and semantics C. An alphabet, a lexis, phonetics, and semantics D. An alphabet, phonetics, phonology, and semantics

B. An alphabet, a lexis, a syntax, and semantics

Which of the following statements are true? (Select two answers) A. The result of the / operator is always an integer value. B. The ** operator uses right-sided binding. C. Adding precedes multiplication. D. The right argument of the % operator cannot be zero.

B. The ** operator uses right-sided binding D. The right argument of the % operator cannot be zero.

What is the output of the following snippet? my_list_1 = [1, 2, 3] my_list_2 = [] for v in my_list_1: my_list_2.insert(0, v) print(my_list_2) A. [1, 2, 3] B. [3, 2, 1] C. [3, 3, 3] D. [1, 1, 1]

B. [3, 2, 1]

Which of the following variable names are illegal? (Select two answers) A. true B. and C. TRUE D. True

B. and D. True

The print() function can output values of: A. not more than five arguments B. any number of arguments (including zero) C. any number of arguments (excluding zero) D. just one argument

B. any number of arguments (including zero)

The 0o prefix means that the number after it is denoted as: A. hexadecimal B. octal C. decimal D. binary

B. octal

The meaning of the keyword parameter is determined by: A. its value B. the argument's name specified along with its value C. its connection with existing variables D. its position within the argument list

B. the argument's name specified along with its value

How many hashes(#) will the following snippet send to the console? var = 0 while var < 6: var += 1 if var % 2 == 0: continue print("#") A. zero B. three C. two D. one

B. three

What is the output of the following snippet? z = y = x = 1 print(x, y, z, sep='*') A. 1 1 1 B. x*y*z C. 1*1*1 D. x y z

C. 1*1*1

What is the output of the following snippet? x = 1 / 2 + 3 // 3 + 4 ** 2 print(x) A. 8.5 B. 0 C. 17.5 D. 17

C. 17.5

What is the output of the following snippet? x = 1 y = 2 z = x x = y y = z print(x, y) A. 1 2 B. 1 1 C. 2 2 D. 2 1

C. 2 2

An operator able to check whether two values are equal is coded as: A. = B. != C. == D. ===

C. ==

What is machine code? A. A high-level programming language consisting of instruction lists that humans can read and understand B. A medium-level programming language consisting of the assembly code designed for the computer processor C. A low-level programming language consisting of binary digits/bits that the computer reads and understands D. A low-level programming language consisting of hexadecimal digits that make up high-level language instructions

C. A low-level programming language consisting of binary digits/bits that the computer reads and understands

What is the best definition of a script? A. It's an error message generated by the interpreter B. It's an error message generated by the compiler C. It's a text file that contains which make up a Python program D. It's a text file that contains sequences of zeroes and ones

C. It's a text file that contains which make up a Python program

What is CPython? A. It's the default, reference implementation of the C language, written in Python B. It's a programming language that is a supperset of the Python, designed to produce C-like performance with code written in Python C. It's the default, reference implementation of Python, written in the C language D. It's a programming that is a superset of the C language, designed to produce Python-like performance with code written in C

C. It's the default, reference implementation of Python, written in the C language

The value eventually assigned to x is equal to: x = 1 x = x == x A. 0 B. 1 C. True D. False

C. True

What value will be assigned to the x variable? z = 10 y = 0 x = y < z and z > y or y > z and z < y A. 1 B. 0 C. True D. False

C. True

What is the output of the following snippet? my_list = [1, 2, 3] for v in range(len(my_list)): my_list.insert(1, my_list[v]) print(my_list) A. [1, 2, 3, 1, 2, 3] B. [1, 2, 3, 3, 2, 1] C. [1, 1, 1, 1, 2, 3] D. [3, 2, 1, 1, 2, 3]

C. [1, 1, 1, 1, 2, 3]

The \n digraph forces the print() function to: A. stop its execution B. duplicate the character next to the digraph C. break the output line D. output exactly two characters: \ and n

C. break the output line

How many hashes(#) will the following snippet send to the console? var = 1 while var < 10: print("#") var = var << 1 A. two B. eight C. four D. one

C. four

How many stars(*) will the following snippet send to the console? var = 0 while i <= 5: i += 1 if i % 2 == 0: break print("*") A. three B. two C. one D. zero

C. one

The ** operator: A. does not exist B. performs duplicated multiplication C. performs exponentiation D. perform floating-point multiplication

C. performs exponentiation

What is the output of the following snippet? def fun(x): if x % 2 == 0: return 1 else: return print(fun(fun(2)) + 1) A. 1 B. None C. the code will cause a runtime error D. 2

C. the code will cause a runtime error

How many hashes(#) will the following snippet send to the console? for i in range(1): print("#") else: print("#") A. zero B. three C. two D. one

C. two

What is the output of the following snippet if the user enters two lines containing 11 and 4 respectively? x = int(input()) y = int(input()) x = x % y x = x % y y = y % x print(y) A. 3 B. 2 C. 4 D. 1

D. 1

What is the output of the following snippet? my_list = [3, 1, -2] print(my_list[my_list(-1)]) A. -2 B. -1 C. 3 D. 1

D. 1

What is the output of the following snippet? a = 1 b = 0 c = a & b d = a | b e = a ^ b print(c + d + e) A. 1 B. 0 C. 3 D. 2

D. 2

The value twenty point twelve times ten raised to the power of eight should be written as: A. 20.12*10^8 B. 20E12.8 C. 20.12E8.0 D. 20.12E8

D. 20.12E8

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = input() y = input() print(x + y) A. 4 B. 2 C. 6 D. 24

D. 24

What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) print(x + y) A. 2 B. 24 C. 4 D. 6

D. 6

What is the output of the following snippet? my_list = [1, 2, 3, 4] print(my_list[-3:-2]) A. [2, 3] B. [2, 3, 4] C. [] D. [2]

D. [2]

What code would you insert instead of the comment to obtain the expected output? Expected output: a b c Code: dictionary = {} my_list = ['a', 'b', 'c', 'd'] for i in range(len(my_list) - 1): dictionary[my_list[i]] = (my_list[i], ) for i in sorted(dictionary.key()): k = dictionary[i] Insert your code here. print(k["0"]) print(k['0']) print(k) print(k[0]) A. print(k["0"]) B. print(k['0']) C. print(k) D. print(k[0])

D. print(k[0])

What is the output of the following snippet? my_list = [[0, 1, 2, 3] for i in range(2)] print(my_list[2][0]) A. 1 B. 2 C. 0 D. the snippet will cause a runtime error

D. the snippet will cause a runtime error


संबंधित स्टडी सेट्स

Marketing Research: Swift and Snug Furniture

View Set

Organizational Behavior & Theory (OB) Exam 2

View Set

Mental health Exam #2 Substance abuse

View Set

Series 7: Part 2 Unit 4 Debt Securities

View Set