What is the expected output of the following code?
What is the expected output of the following code? x = [0, 1, 2] x.insert(0, 1) del x[1] print(sum(x))A . 3 B. 2 C. 4 D. 5View AnswerAnswer: C Explanation: Topics: insert() del sum() list Try it yourself: x = [0, 1, 2] x.insert(0, 1) print(x) # [1, 0, 1,...
What will be the output of the following code snippet?
What will be the output of the following code snippet? d = {} d[1] = 1 d['1'] = 2 d[1] += 1 sum = 0 for k in d: sum += d[k] print(sum)A . 3 B. 4 C. 1 D. 2View AnswerAnswer: B Explanation: Topics: for dictionary indexes add and...
What is the output of the following snippet?
What is the output of the following snippet? def fun(x, y, z): return x + 2 * y + 3 * z print(fun(0, z=1, y=3))A . the snippet is erroneous B. 9 C. 0 D. 3View AnswerAnswer: B Explanation: Topics: positional parameter keyword parameter operator precedence Try it yourself: def...
What is the expected output of the following code?
What is the expected output of the following code? def func(num): res = '*' for _ in range(num): res += res return res for x in func(2): print(x, end='')A . ** B. The code is erroneous. C. * D. ****View AnswerAnswer: D Explanation: Topics: def return for Try it yourself:...
if ???
What would you insert instead of so that the program checks for even numbers? if ???: print('x is an even number')A . x % x == 0 B. x % 1 == 2 C. x % 2 == 0 D. x % 'even' == True E. x % 2 ==...
What is the expected output of the following code?
What is the expected output of the following code? x = ''' print(len(x))A . 1 B. 2 C. The code is erroneous. D. 0View AnswerAnswer: A Explanation: Topics: len() escaping Try it yourself: print(len(''')) # 1 The backslash is the character to escape another character. Here the backslash escapes the...
The result of the following addition:
The result of the following addition: 123 + 0.0A . cannot be evaluated B. is equal to 123.0 C. is equal to 123View AnswerAnswer: B Explanation: Topics: addition operator integer float Try it yourself: print(123 + 0.0) # 123.0 If you have an arithmetic operation with a float, the result...
What is the expected output of the following code?
What is the expected output of the following code? def func(text, num): while num > 0: print(text) num = num - 1 func('Hello', 3)A . An infinite loop. B. Hello Hello Hello C. Hello Hello Hello Hello D. Hello HelloView AnswerAnswer: A Explanation: Topics: def while indentation Try it yourself:...
What is the expected output of the following code?
What is the expected output of the following code? num = 1 def func(): num = num + 3 print(num) func() print(num)A . 4 1 B. 4 4 C. The code is erroneous. D. 1 4 E. 1 1View AnswerAnswer: C Explanation: Topics: def shadowing Try it yourself: num =...
What will happen when you attempt to run the following code?
What will happen when you attempt to run the following code? print(Hello, World!)A . The code will raise the SyntaxError exception. B. The code will raise the TypeError exception. C. The code will raise the ValueError exception. D. The code will print Hello, World! to the console. E. The code...