PYTHON 1 - NETACAD
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
0
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
0
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
0 1
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) > 333333 > 36 > 18 > 666
333333
An operator able to check two values are not equal is code as: > =/= > != > <> > not ==
!=
Which of the following variable names are illegal? (Select two answers) > true > and > TRUE > True
- and - True
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)
- fun(0, 1, 2) - fun(b=0, a=0)
Which of the following lines properly starts a function using two parameters, both with zeroed default values? > def fun (a=b=0) : > def fun (a=0, b=0) : > fun fun (a=0, b) : > fun fun (a, b=0) :
def fun (a=0, b=0) :
Which one if the following lines properly starts a parameterless function definition? > def fun: > def fun(): > function fun(): > fun function():
def fun():
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.
except: (TypeError, ValueError, ZeroDivisinError):# Some code.
How many hashes(#) will the following snippet send to the console? var = 1 while var < 10: print("#") var = var << 1 > two > eight > four > one
four
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
will crate a runtime error
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)) > will output 2 > will output 16 > will output 4 > is erroneous
will output 16
How many element does the lst list contain? lst = [i for i in range(-1, -2)] > two > three > zero > one
zero
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)
21
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 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) > 4 > 2 > 6 > 24
24
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] > 3 > 4 > 2 > 5
4
What is the output o the following snippet? def fun(x): x += 1 return x x = 2 x = fun(x + 1) print(x) > 3 > 5 > the code erroneous > 4
4
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
4
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,)
4
What is the output of the following snippet? def fun(x): global y y = x * x return y fun(2) print(y) > the code will cause a runtime error > 4 > None > 2
4
What is the output of thee following snippet? def fun(inp=2, out=3): return inp * out print(fn(out =2)) > 2 > 6 > 4 > the snippet is erroneous
4
What is the output of the following snippet if the user enter two lines containing 2 and 4 respectively? x = int(input()) y = int(input()) print(x + y) > 2 > 24 > 4 > 6
6
What is the output of the following snippet? def f(x): if x == 0: return 0 return x + f(x - 1) print(f(3)) > 6 > the code is erroneous > 1 > 3
6
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) > 4 > 7 > 02 > 6
6
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
63
What is the output of the following snippet if the user enters two lines containing 2 and 4 respectively? x = int(input()) y = int(intpu()) x = x / y y = y / x print(y) > 8.0 > the code will cause a runtime error > 4.0 > 2.0
8.0
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)) > 9 > 0 > 3 > the snippet is erroneous
9
The result of the following division: 1 / 1 > is equal to 1.0 > is equal to 1 > cannot be evaluated > cannot be predicted
is equal to 1.0
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
is erroneous
The following snippet: def func(a, b): return a ** a print(func(2)) > is erroneous > will output 2 > will output 4 > will return None
is erroneous
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
is illegal
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] > can be executed if and only if the tuple contains at least two elements > is illegal > may be illegal if the tuple contains string > is fully correct
is illegal
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
its position within the argument list
What is the best definition of a script? > It's an error message generated by the interpreter > It's an error message generated by the compiler > It's a text file that contains which make up a Python program > It's a text file that contains sequences of zeroes and ones
It's a text file that contains which make up a Python program
What is CPython? > It's the default, reference implementation of the C language, written in Python > It's a programming language that is a supperset of the Python, designed to produce C-like performance with code written in Python > It's the default, reference implementation of Python, written in the C language > It's a programming that is a superset of the C language, designed to produce Python-like performance with code written in C
It's the default, reference implementation of Python, written in the C language
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 systemError exception. > The code will raise the ValueError exception. > The code will print Hello World to the console. > The code will raise the TyepError exception.
The code will raise the systemError exception
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.
The program will cause a SyntaxError exception
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.
The program will cause a ValueError exception.
What is the expected behavior of the following program? print("Goodbye!") > The program will output Goodbye! to the screen > The program will generate an error message on the screen > The program will output("Goodbye!") > The program will output "Goodbye!"
The program will generate an error message on the screen
What is the expected behavior of the following program? print("Hello!") > The program will output ("Hello!") to the screen > The program will generate an error message on the screen > The program will output Hello! to the screen > The program will output "Hello!" to the screen
The program will output Hello! to the screen
The value eventually assigned to x is equal to : x = 1 x = x == x > 0 > 1 > True > False
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 > 1 > 0 > True > False
True
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
True
The print() function can output values of: > not more than five arguments > any number of arguments (including zero) > any number of arguments (excluding zero) > just one argument
any number of arguments (including zero)
What is the output of the following piece of code? print("a", "b", "c", sep="sep") > a b c > abc > asepbsepcsep > asepbsepc
asepbsepc
The \n digraph forces the print() function to: > stop its execution > duplicate the character next to the digraph > break the output line > output exactly two characters: \ and n
break the output line
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
comes with Python, ans is an integer part of Python
What do you call a command-line interpreter which lets you interact with your OS and execute Python commands and scripts? > An editor > A console > A compiler > Jython
console
The meaning of the keyword parameter is determined by: > its value > the argument's name specified along with is value > its connection with exiting variables > its position within the argument list
the argument's name specified along with is value
What is the output of the following snippet if the user enter two lines containing 2and 4 respectively? x = int(intput()) y = int(intput()) x = x // y y = y //x print(y) > the code will cause a runtime error > 2.0 > 8.0 > 4.0
the code will cause a runtime error
What is the output of the following snippet? def fun(x): if x % 2 == 0: return 1 else: return print(fun(fun(2)) + 1) > 1 > None > The code will cause a runtime error > 2
the code will cause a runtime error
What is the output of the following snippet? my_list = [[0, 1, 2, 3] for i in rage(2)] print(my_list[2][0]) > 1 > 2 > 0 > the snippet will cause a runtime error
the snippet will cause a runtime error
What is the output of the following snippet? y = 2 + 3 * 5. print(Y) > the snippet will cause an execution error > 25. > 17 > 17.0
the snippet will cause an execution error
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
they can be indexed and sliced like lists
How many elements does the my_list list contain? my_list = [i for i in range(-1, 2)] > two > three > four > one
three
How many hashes(#) will the following snippet send to the console? var = 0 while var < 6: var += 1 if var % 2 == 0: continue print("#") > zero > three > two > one
three
How many hashes(#) will the following snippet send to the console? for i in range(1): print("#") else: print("#") > zero > three > two > one
two
How many stars (*) will the following snippet send to the console? i = 0 while i <= 3 : i += 2 print("+") > three > zero > one > two
two
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) > three > one > ('one', 'two', 'three') > two
two
An operator able to check whether two values are equal is code as: > = > != > == > ===
==
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)
the code is erroneous(the dict object has no vals() method)
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
the snippet will enter an infinite loop, printing one star per line
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
three
The value twenty point twelve times ten raised to the power of eight should be written as: > 20.12*10^8 > 20E12.8 > 20.12E8.0 > 20.12Eo
20.12Eo
Select the true statements? (Select two answer) > Python is a good choice for creating and executing tests for applications > Python 3 is backwards compatible with Python 2 > Python is a good choice for low-level programming e.g., when you want to implement an effective driver > Python is free, open-source, and multiplatform
- Python is a good choice for creating and executing tests for applications - Python is free, open-source, and multiplatform
Which of the following statement are true? (Select two answers) > The result of the / operator is always an integer value. > The ** operator uses right-sided binding. > Adding precedes multiplication. > The right argument of the % operator cannot be zero.
- The ** operator uses right-sided binding. - The right argument of the % operator cannot be zero.
Which of the following statement are true? (Select two answers) > The None value can be assigned to variables > The None value cannot be used outside functions > The None value can be used as an argument of arithmetic operators > The None value can be compared with variables
- The None value can be assigned to variables - The None value can be compared with variables
What is true compilation? (Select two answer) > Both you and user must have the compiler to run your code > The code is converted directly into machine code executable by the processor > It tends to be faster than interpretation > It tends to be than interpretation
- The code is converted directly into machine code executable by the processor - It tends to be faster than interpretation
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... > if you suspect that a snippet may raise an exception, you should place it in the try block > The code that follows the try statement will be executed if the code in the except clause runs into an error. > The code that follows the except statement will be executed if the code in the try clause runs into an error. > If there is a syntax error in code located in the try block, the except branch will not handle it, and a SyntaxError exception
- if you suspect that a snippet may raise an exception, you should place it in the try block - The code that follows the except statement will be executed if the code in the try clause runs into an error.
Which of the following variable names are illegal and will cause the SystemError exception? (Select two answers) > print > in > for > in
- in - for
A function defined in the following way: (Select two answers) def function(x=0): return x > may be invoked with exactly one argument > must be invoked with exactly one argument > must be invoked without any argument > may be invoked without any argument
- may be invoked with exactly one argument - may be invoked without any argument
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
- nums and vals are different names of the same list - nums has the same length as vals
Take a look at the snippet, and choose the true statements: (Select two answer) nums = [1, 2, 3] vals = nums del vals[1:2] > nums is longer than vals > nums and vals are of the same length > nums and vals refer to the same list > nums is replicated and assigned to vals
- nums and vals are of the same - nums and vals refer to the same list
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 > numsis longer than vals
- nums and vals are two different lists - numsis longer than vals
Left-sided binding determines that the result of the following expression: 1 // 2 * 3 is equal to : > 0.0 > 0 > 4.5 > 0.166666666666666666
0
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
0.0
What is the output of the following piece of code? x = 1 // 5 + 1 / 5 print(x) > 0.0 > 0 > 0.4 > 0.2
0.2
What is the output of the following snippet? my_list = [3, 1, -2] print(my_list[my_list(-1)]) > -2 > -1 > 3 > 1
1
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
1 1 2
What is the output of the following snippet? z = y = x = 1 print(x, y, z, sep='*') > 1 1 1 > x*y*z > 1*1*1 > x y z
1*1*1
What is the output of the following snippet? x = 1 / 2 + 3 // 3 + 4 **2 print(x) > 8.5 > 0 > 17.5 > 17
17.5
What is the output of the following snippet? a = 1 b = 0 c = a & b d = a | be = a ^ b print(c + d + e) > 1 > 0 > 3 > 2
2
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
2
What is the output of the following snippet? tup = (1, 2, 4, 8) tup = tup[1:-1] tup = tup[0] print(tup) > the snippet is erroneous > (12) > (2, ) > 2
2
What is the output of the following snippet? x = 1 y = 2 z = x x = y y = z print (x, y) > 1 2 > 1 1 > 2 2 > 2 2
2 2
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
2.0
What is machine code? > A high-level programming language consisting of instruction lists that humans can read and understand > A medium-level programming language consisting of the assembly code designed for the computer processor > A low-level programming language consisting of binary digits/bits that the computer reads and understands > A low-level programming language consisting of hexadecimal digits that make up high-level language instructions
A low-level programming language consisting of binary digits/bits that the computer reads and understands
What do you call a file containing a program written in a high-level programming language? > A machine file > A code file > A target file > A source file
A source file
What are the four fundaments elements the make a language? > An alphabet, morphology, phonetics, and semantics > An alphabet, a lexis, a syntax, and semantics > An alphabet, a lexis, phonetics, and semantics > An alphabet, phonetics, phonology, and semantics
An alphabet, a lexis, a syntax, and semantics
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...
Very very bad input...
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]
[0 , 1, 4, 9]
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) > [1, 2, 3, 1, 2, 3] > [1, 2, 3, 3, 2, 1] > [1, 1, 1, 1, 2, 3] > [3, 2, 1, 1, 2, 3]
[1, 1, 1, 1, 2, 3]
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]
[1, 1, 1, 2]
What is the output of the following snippet? my_list = [1, 2, 3, 4] print(my_list[-3:-2]) > [2, 3] > [2, 3, 4] > [] > [2]
[2]
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) > [1, 2, 3] > [3, 2, 1] > [3, 3, 3] > [1, 1, 1]
[3, 2, 1]
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)) > ['Mary', 'had', 'a' ,'lamb'] > ['Mary', 'had', 'a' ,'ram'] > ['Mary', 'had', 'a' ,'little', 'lamb'] > no output, the snippet is erroneous
no output, the snippet is erroneous
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
nums and vals have the same length
The 80 prefix means that the number after it is denoted as: > hexadecimal > octal > decimal > binary
octal
How many stars(#) will the following snippet send to the console? var = 0 while i <= 5: i += 1 if vi % 2 == 0: break print("*") > three > two > one > zero
one
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
one
The ** operator: > does not exist > performs duplicated multiplication > performs exponentiation > perform floating-point multiplication
performs exponentiation
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])
print(k[0])
The second assignment: vals = [0, 1, 2] vals[0], vlas[2] = vals[2], vals[0] > doesn't change the list > reverses the list > shortens the list > extends the list
reverses the list