Quiznetik
Problem Solving and Python Programming | Set 5
1. What is called when a function is defined inside a class?
A. module
B. class
C. another function
D. method
Correct : D. method
2. Lambda contains block of statements.
A. true
B. false
Correct : B. false
3. f(2, 30, 400)
A. 432
B. 24000
C. 430
D. no output
Correct : A. 432
4. who('Arthur')
A. arthur sir
B. sir arthur
C. arthur
D. none of the mentioned
Correct : B. sir arthur
5. min(101*99, 102*98)
A. 9997
B. 9999
C. 9996
D. none of the mentioned
Correct : C. 9996
6. ) print(i)
A. 1
B. nothing is displayed
C. 0
D. an exception is thrown
Correct : C. 0
7. 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
Correct : C. two stars followed by a valid identifier
8. , 2, 3])
A. 3 1
B. 1 3
C. error
D. none of the mentioned
Correct : A. 3 1
9. print(foo())
A. 0
B. 1
C. error
D. none of the mentioned
Correct : C. error
10. How are variable length 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
Correct : A. one star followed by a valid identifier
11. 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
Correct : C. the program’s name
12. How are default arguments specified in the function heading?
A. identifier followed by an equal to sign and the default value
B. identifier followed by the default value within backticks (“)
C. identifier followed by the default value within square brackets ([])
D. identifier
Correct : A. identifier followed by an equal to sign and the default value
13. Where are the arguments received from the command line stored?
A. sys.argv
B. os.argv
C. argv
D. none of the mentioned
Correct : A. sys.argv
14. san(12)
A. 13
B. 10
C. 2
D. 5
Correct : A. 13
15. , 5])?
A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
B. [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
C. [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
D. [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
Correct : A. [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
16. print(len(numbers))
A. 4
B. 5
C. 8
D. 12
Correct : B. 5
17. 2 TUPLES (TUPLE ASSIGNMENT, TUPLE AS RETURN VALUE)
A. [1, 2, 3]
B. (1, 2, 3)
C. {1, 2, 3}
D. {}
Correct : B. (1, 2, 3)
18. >>>2 * t
A. (1, 2, 1, 2)
B. [1, 2, 1, 2]
C. (1, 1, 2, 2)
D. [1, 1, 2, 2]
Correct : A. (1, 2, 1, 2)
19. ,2,3
A. yes, this is an example of tuple unpacking. a=1 and b=2
B. yes, this is an example of tuple unpacking. a=(1,2) and b=3
C. no, too many values to unpack
D. yes, this is an example of tuple unpacking. a=1 and b=(2,3)
Correct : C. no, too many values to unpack
20. ] test[1] = 'D' del test[2] print(len(test))
A. 0
B. 2
C. error as the key-value pair of 1:’a’ is already deleted
D. 1
Correct : B. 2
21. print(a)
A. true
B. false
Correct : B. false
22. 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”)
Correct : B. infile = open(“c:\\scores.txt”, “r”)
23. To read the remaining lines of the file from a file object infile, we use
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
Correct : D. infile.readlines()
24. 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
Correct : A. remove(file_name)
25. Which of the following mode will refer to binary data?
A. r
B. w
C. +
D. b
Correct : D. b
26. What is the difference between r+ and w+ modes?
A. no difference
B. in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
C. in w+ the pointer is initially placed at the beginning of the file and the pointer is at the end for r+
D. depends on the operating system
Correct : B. in r+ the pointer is initially placed at the beginning of the file and the pointer is at the end for w+
27. How do you get the name of a file from a file object (fp)?
A. fp.name
B. fp.file(name)
C. self. name (fp)
D. fp. name ()
Correct : A. fp.name
28. Which function overloads the + operator?
A. add ()
B. plus ()
C. sum ()
D. none of the mentioned
Correct : A. add ()
29. k = foo() print(k)
A. 1
B. 2
C. 3
D. error, there is more than one return statement in a single try-finally block
Correct : B. 2
30. g=f(8) print(next(g))
A. 8
B. 9
C. 7
D. error
Correct : B. 9