Question
Q: Please answer each You are given a read only array of n integers from 1 to n. Each integer appears exactly once except A
Q:
Please answer each
You are given a read only array of n integers from 1 to n.
Each integer appears exactly once except A which appears twice and B which is missing.
Return A and B.
Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Note that in your output A should precede B.
Example:
Input:[3 1 2 5 3]
Output:[3, 4]
A = 3, B = 4
Please use python 3.5+ for answering above coding question and explanation for each of the below mcqs should be clear. Please don't copy from anywhere. Thanks in advance!!
1. To open a file c:\scores.txt for reading, we use _____________
a) infile = open("c:\scores.txt", "r")
b) infile = open("c:\\scores.txt", "r")
c) infile = open(file = "c:\scores.txt", "r")
d) infile = open(file = "c:\\scores.txt", "r")
2. What will be the output of the following Python code?
x=10
y=8
assert x>y, 'X too small'
a) Assertion Error
b) 10 8
c) No output
d) 108
3. The function used to alter the thickness of the pen to 'x' units:
a) turtle.width(x)
b) turtle.span(x)
c) turtle.girth(x)
d) turtle.thickness(x)
4. Which is the most appropriate definition for recursion?
a) A function that calls itself
b) A function execution instance that calls another execution instance of the same function
c) A class method that calls another class method
d) An in-built method that is automatically called
5. Overriding means changing behaviour of methods of derived class methods in the base class.
a) True
b) False
6. How are keyword arguments specified in the function heading?
a) one-star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier
7. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
a) {1: 'A', 2: 'B', 3: 'C'}
b) Method update() doesn't exist for dictionaries
c) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
d) {4: 'D', 5: 'E'}
8. What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
for i in a:
print(i,end=" ")
a) 1 2 3
b) 'A' 'B' 'C'
c) 1 'A' 2 'B' 3 'C'
d) Error, it should be: for i in a.items():
9. Does Lambda contains return statements?
a) True
b) False
10. The command which helps us to reset the pen (turtle):
a) turtle.reset
b) turtle.penreset
c) turtle.penreset()
d) turtle.reset()
11. What will be the output of the following Python code?
str = input("Enter your input: ");
print "Received input is : ", str
a)
Enter your input: [x*5 for x in range(2,10,2)]
Received input is :[x*5 for x in range(2,10,2)]
b)
Enter your input: [x*5 for x in range(2,10,2)]
Received input is :[10, 30, 20, 40]
c)
Enter your input: [x*5 for x in range(2,10,2)]
Received input is :[10, 10, 30, 40]
d) None of the mentioned
12. What does print(Test.name) display (assuming Test is the name of the class)?
a) ()
b) Exception is thrown
c) Test
d) main
13. What will be the output of the following Python code?
#mod1
def change(a):
b=[x*2 for x in a]
print(b)
#mod2
def change(a):
b=[x*x for x in a]
print(b)
from mod1 import change
from mod2 import change
#main
s=[1,2,3]
change(s)
a) [2,4,6]
b) [1,4,9]
c)
[2,4,6]
[1,4,9]
d) There is a name clash
14. What will be the output of the following Python code?
def f(p, q, r):
global s
p = 10
q = 20
r = 30
s = 40
print(p,q,r,s)
p,q,r,s = 1,2,3,4
f(5,10,15)
a) 1 2 3 4
b) 5 10 15 4
c) 10 20 30 40
d) 5 10 15 40
15. What is returned by math.isfinite(float('inf'))?
a) True
b) False
c) None
d) error
16. The output of the following two Python codes are the same.
CODE 1
>>> re.split(r'(a)(t)', 'The night sky')
CODE 2
>>> re.split(r'\s+', 'The night sky')
a) True
b) False
17. ______ is a string literal denoted by triple quotes for providing the specifications of certain program elements.
a) Interface
b) Modularity
c) Client
d) Docstring
18. What will be the output of the following Python code?
def foo(x):
x = ['def', 'abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) True
b) False
c) None
d) Error
19. Which function is used to read single line from file?
a) Readline()
b) Readlines()
c) Readstatement()
d) Readfullline()
20. What will be the output of the following Python function?
all([2,4,0,6])
a) Error
b) True
c) False
d) 0
21. What will be the output of the following Python code?
L = [lambda x: x2,
lambda x: x3,
lambda x: x ** 4]
for f in L:
print(f(3))
a)
27
81
343
b)
6
9
12
c)
9
27
81
d) None of the mentioned
22. What is called when a function is defined inside a class?
a) Module
b) Class
c) Another function
d) Method
23. What is the type of sys.argv?
a) set
b) list
c) tuple
d) string
24. What does the function re.match do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
25. What will be the output of the following Python code?
def to_upper(k):
k.upper()
x = ['ab', 'cd']
print(list(map(to_upper, x)))
a) ['AB', 'CD']
b) ['ab', 'cd']
c) none of the mentioned
d) error
26. What will be the output shape of the following Python code?
import turtle
t=turtle.Pen()
for i in range(1,4):
t.forward(60)
t.left(90)
a) Rectangle
b) Trapezium
c) Triangle
d) Square
27. What will be the output of the following Python code?
x=1
def cg():
global x
x=x+1
cg()
x
a) 2
b) 1
c) 0
d) Error
28. What will be the output of the following Python code?
x=100
def f1():
global x
x=90
def f2():
global x
x=80
print(x)
a) 100
b) 90
c) 80
d) Error
29. What will be the output of the following Python code?
class Demo:
def check(self):
return " Demo's check "
def display(self):
print(self.check())
class Demo_Derived(Demo):
def check(self):
return " Derived's check "
Demo().display()
Demo_Derived().display()
a) Demo's check Derived's check
b) Demo's check Demo's check
c) Derived's check Demo's check
d) Syntax error
30. Which of the following is not an exception handling keyword in Python?
a) try
b) except
c) accept
d) finally
31. The output of the following Python code is either 1 or 2.
import random
random.randint(1,2)
a) True
b) False
32. What will be the output of the following Python function?
re.findall("hello world", "hello", 1)
a) ["hello"]
b) [ ]
c) hello
d) hello world
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started