Home
MCQS
MCQs Practice Portal - thefunword.com
Python MCQ Quiz Hub
Python Mcq Set 16
Choose a topic to test your knowledge and improve your Python skills
1. What the does random.seed(3) return?
True
None
3
1
2. Which of the following cannot be returned by random.randrange(4)?
0
3
2.3
none of the mentioned
3. Which of the following is equivalent to random.randrange(3)?
range(3)
random.choice(range(0, 3))
random.shuffle(range(3))
random.select(range(3))
4. The function random.randint(4) can return only one of the following values. Which?
4
3.4
error
5
5. Which of the following is equivalent to random.randint(3, 6)?
random.choice([3, 6])
random.randrange(3, 6)
3 + random.randrange(3)
3 + random.randrange(4)
6. Which of the following will not be returned by random.choice(“1 ,â€)?
1
(space)
,
none of the mentioned
7. Which of the following will never be displayed on executing print(random.choice({0: 1, 2: 3}))?
0
1
KeyError: 1
none of the mentioned
8. What does random.shuffle(x) do when x = [1, 2, 3]?
error
do nothing, it is a placeholder for a function that is yet to be implemented
shuffle the elements of the list in-place
none of the mentioned
9. Which type of elements are accepted by random.shuffle()?
strings
lists
tuples
integers
10. What is the range of values that random.random() can return?
[0.0, 1.0]
(0.0, 1.0]
(0.0, 1.0)
[0.0, 1.0)
11. Which of the following functions is not defined under the sys module?
sys.platform
sys.path
sys.readline
sys.argv
12. What will be the output of the following Python code, if the code is run on Windows operating system? import sys if sys.platform[:2]== 'wi': print("Hello")
Error
Hello
No output
Junk value
13. What will be the output of the following Python code, if the sys module has already been imported? sys.stdout.write("hello world")
helloworld
hello world10
hello world11
error
14. What will be the output of the following Python code? import sys sys.stdin.readline() Sanfoundry
‘Sanfoundry ’
‘Sanfoundry’
‘Sanfoundry10’
Error
15. What will be the output of the following Python code? import sys eval(sys.stdin.readline()) "India"
India5
India
‘India ’
‘India’
16. What will be the output of the following Python code? import sys eval(sys.stdin.readline()) Computer
Error
‘Computer ’
Computer8
Computer
17. What will be the output of the following Python code? import sys sys.argv[0]
Junk value
‘ ‘
No output
error
18. What will be the output of the following Python code? import sys sys.stderr.write(“helloâ€)
‘hello’
‘hello ’
hello
hello5
19. To obtain a list of all the functions defined under sys module, which of the following functions can be used?
print(sys)
print(dir.sys)
print(dir[sys])
print(dir(sys))
20. The output of the function len(sys.argv) is _____
Error
1
0
Junk value
21. What does os.name contain?
the name of the operating system dependent module imported
the address of the module os
error, it should’ve been os.name()
None of the mentioned
22. What does print(os.geteuid()) print?
the group id of the current process
the user id of the current process
both the group id and the user of the current process
none of the mentioned
23. What does os.getlogin() return?
name of the current user logged in
name of the superuser
gets a form to login as a different user
all of the mentioned
24. What does os.close(f) do?
terminate the process f
terminate the process f if f is not responding
close the file descriptor f
return an integer telling how close the file pointer is to the end of file
25. What does os.fchmod(fd, mode) do?
change permission bits of the file
change permission bits of the directory
change permission bits of either the file or the directory
none of the mentioned
26. Which of the following functions can be used to read data from a file using a file descriptor?
os.reader()
os.read()
os.quick_read()
os.scan()
27. Which of the following returns a string that represents the present working directory?
os.getcwd()
os.cwd()
os.getpwd()
os.pwd()
28. What does os.link() do?
create a symbolic link
create a hard link
create a soft link
none of the mentioned
29. Which of the following can be used to create a directory?
os.mkdir()
os.creat_dir()
os.create_dir()
os.make_dir()
30. Which of the following can be used to create a symbolic link?
os.symlink()
os.symb_link()
os.symblin()
os.ln()
31. What will be the output shape of the following Python code? import turtle t=turtle.Pen() for i in range(0,4): t.forward(100) t.left(120)
square
rectangle
triangle
kite
32. The number of lines drawn in each case, assuming that the turtle module has been imported: Case 1: for i in range(0,10): turtle.forward(100) turtle.left(90) Case 2: for i in range(1,10): turtle.forward(100) turtle.left(90)
10, 9
9, 10
9, 9
10, 10
33. The command which helps us to reset the pen (turtle):
turtle.reset
turtle.penreset
turtle.penreset()
turtle.reset()
34. Fill in the blank such that the following Python code results in the formation of an inverted, equilateral triangle. import turtle t=turtle.Pen() for i in range(0,3): t.forward(150) t.right(_____)
-60
120
-120
60
35. 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)
Rectangle
Trapezium
Triangle
Square
36. What will be the output of the following Python code? import turtle t=turtle.Pen() for i in range(0,4): t.forward(100) t.left(90) t.penup() t.left(90) t.forward(200) for i in range(0,4): t.forward(100) t.left(90)
Error
1 square
2 squares, at a separation of100 units, joined by a straight line
2 squares, at a separation of 100 units, without a line joining them
37. Which of the following functions does not accept any arguments?
position
fillcolor
goto
setheading()
38. What will be the output of the following Python code? import turtle t=turtle.Pen() t.goto(300,9) t.position()
300.00, 9.00
9, 300
300, 9
9.00, 300.00
39. What will be the output of the following Python code? import turtle t=turtle.Pen() for i in range(0,5): t.left(144) t.forward(100)
Trapezium
Parallelepiped
Tetrahedron
Star
40. What will be the output of the following Python functions? import turtle t=turtle.Pen() for i in range(0,3): t.forward(100) t.left(120) t.back(100) for i in range(0,3): t.forward(100) t.left(120)
Error
Two triangles, joined by a straight line
Two triangles, joined at one vertex
Two separate triangles, not connected by a line
41. 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()
Error
A circle filled in with the colour red
A circle filled in with the colour blue
A circle filled in with the colour green
42. Which of the following functions can be used to make the arrow black?
turtle.color(0,1,0)
turtle.color(1,0,0)
turtle.color(0,0,1)
turtle.color(0,0,0)
43. hat will be the output of the following Python code? import turtle t=turtle.Pen() t.color(1,1,1) t.begin_fill() for i in range(0,3): t.forward(100) t.right(120) t.end_fill()
Blank page
A triangle filled in with the colour yellow
A triangle which is not filled in with any colour
error
44. What will be the output of the following Python code? import turtle t=turtle.Pen() t.color(0,1,0) t.begin_fill() for i in range(0,4): t.forward(100) t.right(90)
A square filled in with the colour green
A square outlined with the colour green
Blank canvas
error
45. In which direction is the turtle pointed by default?
North
South
East
West
46. The command used to set only the x coordinate of the turtle at 45 units is:
reset(45)
setx(45)
xset(45)
xreset(45)
47. Which of the following functions returns a value in degrees, counterclockwise from the horizontal right?
heading()
degrees()
position()
window_height()
48. What will be the output of the following Python code? import turtle t=turtle.Pen() t.right(90) t.forward(100) t.heading()
0.0
90.0
270.0
360.0
49. What will be the output of the following Python code? import turtle t=turtle.Pen() t.clear() t.isvisible()
Yes
True
No
False
50. What will be the output of the following Python code? import turtle t=turtle.Pen() t.forward(100) t.left(90) t.clear() t.position()
0.00, 90.00
0.00, 0.00
100.00, 90.00
100.00, 100.00
Submit