Question
Given an integer A, generate a square matrix filled with elements from 1 to A^2 in spiral order. Input Format: The first and the only
Given an integer A, generate a square matrix filled with elements from 1 to A^2 in spiral order.
Input Format:
The first and the only argument contains an integer, A.
Output Format:
Return a 2-d matrix of size A x A satisfying the spiral order.
Constraints:
1 <= A <= 1000
Examples:
Input 1:
A = 3
Output 1:
[ [ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ] ]
Input 2:
4
Output 2:
[ [1, 2, 3, 4],
[12, 13, 14, 5],
[11, 16, 15, 6],
[10, 9, 8, 7] ]
Python code and mcq explanation needed. Please don't copy from anywhere
1. What will be the output of the following Python code?
def sayHello():
print('Hello World!')
sayHello()
sayHello()
a)
Hello World!
Hello World!
b)
'Hello World!'
'Hello World!'
c)
Hello
Hello
advertisement
d) None of the mentioned
2. What is the default base used when math.log(x) is found?
a) e
b) 10
c) 2
d) none of the mentioned
3. What will be the output of the following Python code?
list(map((lambda x:x^2), range(10)))
a) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
b) Error
c) [2, 3, 0, 1, 6, 7, 4, 5, 10, 11]
d) No output
4. What will be the output of the following Python functions?
float('1e-003')
float('2e+003')
a)
3.00
300
b)
0.001
2000.0
c)
0.001
200
d)
Error
2003
5. What is the value stored in sys.argv[0]?
a) null
b) you cannot access it
c) the program's name
d) the first argument
6. What will be the output of the following Python code snippet?
total={}
def insert(items):
if items in total:
total[items] += 1
else:
total[items] = 1
insert('Apple')
insert('Ball')
insert('Apple')
print (len(total))
a) 3
b) 1
c) 2
d) 0
7. Which of the following aren't defined in the math module?
a) log2()
b) log10()
c) logx()
d) none of the mentioned
8. Which of the following is not an advantage of using modules?
a) Provides a means of reuse of program code
b) Provides a means of dividing up tasks
c) Provides a means of reducing the size of the program
d) Provides a means of testing individual parts of the program
9. What will be the output of the following Python code?
import turtle
t=turtle.Pen()
t.color(0,0,1)
t.begin_fill()
t.circle(15)
t.end_fill()
a) Error
b) A circle filled in with the colour red
c) A circle filled in with the colour blue
d) A circle filled in with the colour green
10. The output of the following two Python codes are the same.
p = re.compile('hello')
r = p.match('hello everyone')
print(r.group(0))
r = re.match('hello', 'hello everyone')
print(r.group(0))
a) True
b) False
11. What will be the output of the following Python code?
l1=[10, 20, 30]
l2=l1
id(l1)==id(l2)
l2=l1.copy()
id(l1)==id(l2)
a) False, False
b) False, True
c) True, True
d) True, False
12. Which of the following functions clears the regular expression cache?
a) re.sub()
b) re.pos()
c) re.purge()
d) re.subn()
13. What will be the output of the following Python code?
class A:
def str(self):
return '1'
class B(A):
def init(self):
super().init()
class C(B):
def init(self):
super().init()
def main():
obj1 = B()
obj2 = A()
obj3 = C()
print(obj1, obj2,obj3)
main()
a) 1 1 1
b) 1 2 3
c) '1' '1' '1'
d) An exception is thrown
14. What happens if no arguments are passed to the seek function?
a) file position is set to the start of file
b) file position is set to the end of file
c) file position remains unchanged
d) error
15. What will be the output of the following Python code?
i=0
def change(i):
i=i+1
return i
change(1)
print(i)
a) 1
b) Nothing is displayed
c) 0
d) An exception is thrown
16. Which function is called when the following Python code is executed?
f = foo()
format(f)
a) format()
b) format()
c) str()
d) str()
17. What is the current syntax of remove() a file?
a) remove(file_name)
b) remove(new_file_name, current_file_name,)
c) remove(() , file_name))
d) none of the mentioned
18. What will be the output of the following Python code?
import sys
eval(sys.stdin.readline())
Computer
a) Error
b) 'Computer '
c) Computer8
d) Computer
19. What will be the output of the following Python code?
import re
s = "A new day"
m = re.match(r'(.*)(.*?)', s)
print(m.group(2))
print(m.group(0))
a)
No output
A new day
b)
No output
No output
c)
['A', 'new', 'day']
('A', 'new', 'day')
d)
Error
['A', 'new', 'day']
20. What will be the output of the following Python code?
class Test:
def init(self):
self.x = 0
class Derived_Test(Test):
def init(self):
self.y = 1
def main():
b = Derived_Test()
print(b.x,b.y)
main()
a) 0 1
b) 0 0
c) Error because class B inherits A but variable x isn't inherited
d) Error because when object is created, argument must be passed like Derived_Test(1)
21. What will be the output of the following Python function if the random module has already been imported?
random.randint(3.5,7)
a) Error
b) Any integer between 3.5 and 7, including 7
c) Any integer between 3.5 and 7, excluding 7
d) The integer closest to the mean of 3.5 and 7
22. What will be the output of the following Python code?
x = [12.1, 34.0]
print(' '.join(list(map(str, x))))
a) 12 1 34 0
b) 12.1 34
c) 121 340
d) 12.1 34.0
23. To sterilize an object hierarchy, the _____________ function must be called. To desterilize a data stream, the ______________ function must be called.
a) dumps(), undumps()
b) loads(), unloads()
c) loads(), dumps()
d) dumps(), loads()
24. Which of the following is the same as math.exp(p)?
a) e p
b) math.e p
c) p e
d) p math.e
25. What is math.factorial(4.0)?
a) 24
b) 1
c) error
d) none of the mentioned
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