What is the expected output of the following code?
What is the expected output of the following code? def func(x): return 1 if x % 2 != 0 else 2 print(func(func(1)))A . The code is erroneous. B. None C. 2 D. 1View AnswerAnswer: D Explanation: Topics: def conditional expression (if else) modulus operator not equal to operator Try it...
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...
How many stars will the following code print to the monitor?
How many stars will the following code print to the monitor? i = 0 while i <= 3: i += 2 print('*')A . one B. zero C. two D. threeView AnswerAnswer: C Explanation: Topic: while Try it yourself: i = 0 while i <= 3: # i=0, i=2 i +=...
What is the expected output of the following code?
What is the expected output of the following code? def func(data): for d in data[::2]: yield d for x in func('abcdef'): print(x, end='')A . bdf B. An empty line. C. abcdef D. aceView AnswerAnswer: D Explanation: Topics: def yield for print() with end parameter list slicing Try it yourself: def...
What will be the output of the following code snippet?
What will be the output of the following code snippet? print(3 / 5)A . 6/10 B. 0.6 C. 0 D. None of the above.View AnswerAnswer: B Explanation: Topic: division operator Try it yourself: print(3 / 5) # 0.6 print(4 / 2) # 2.0 The division operator does its normal job....
What is the output of the following code?
What is the output of the following code? a = 1 b = 0 x = a or b y = not(a and b) print(x + y)A . The program will cause an error B. 1 C. The output cannot be predicted D. 2View AnswerAnswer: D Explanation: Topics: logical operators...
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...