Python One Linear MCQ Quiz for O Level

0%
Question 1: What is the main goal of white box testing?
A) To test the software without knowledge of internal structure.
B) To ensure that the internal operation of a program is functioning as expected.
C) To Test the system's performance under heavy loads.
D) To simulate the interface and user experience.
Question 2: What will be the output of the following python expression? 24//6%3, 24//4//2
A) (1,3)
B) (1,1)
C) (1,9)
D) (1,5)
Question 3: Program code making use of a given module is called a ________of the module
A) Client
B) Docstring
C) Interface
D) Modularity
Question 4: What is called when a function is defined inside a class?
A) Module
B) Class
C) Another function
D) Method
Question 5: In while loop, how can you prevent it from becoming an infinite loop?
A) Use the break statement at the end of the body loop
B) Including an else statement with a termination condition
C) Ensure that the loop condition becomes False at some point
D) Add a continue statement at the beginning of the body loop
Question 6: What is the purpose of NumPy arrange() function?
A) To create a sequence of numbers with a specified step size
B) To create a random array of specified shape and values
C) To create an array of ones with a specified shape
D) To create an array of zeros with a specified shape
Question 7: What is the correct way to open a file in binary read mode in python?
A) open('file.txt', 'b')
B) open('file.txt', 'rb')
C) open('file.txt', 'rbin')
D) open('file.txt', 'read-binary')
Question 8: What will be the data type of the var in the below code snippet?
    var = 10
    print(type(var))
    var = "hello"
    print(type(var))
A) str and int
B) int and int
C) str and str
D) int and str
Question 9: What is the result of the bitwise OR operation between 10 and 6?
A) 4
B) 14
C) 16
D) 24
Question 10: What is the output of the following expression? np.linspace(0,10,5)
A) [0, 2, 4, 6, 8, 10]
B) [0, 2, 4, 6, 8]
C) [0, 2.5, 5, 7.5, 10]
D) [0.0, 2.5, 5.0, 7.5, 10.0]
Question 11: _________ is not a valid namespace
A) Global namespace
B) Public namespace
C) Built-in namespace
D) Local namespace
Question 12: What will be following code output?
    def outer():
        x=5
        def inner():
            nonlocal x
            x=10
        inner()
        print(x)
    outer()
A) 5
B) 10
C) None
D) Error
Question 13: Which of the following option is the correct statement to read and display the first 10 character of a text file "doc.txt"
A) F=open('doc.txt'); print(F.load(10))
B) F=open('doc.txt'); print(F.dump(10))
C) F=open('doc.txt'); print(F.read(10))
D) F=open('doc.txt'); print(F.write(10))
Question 14: Let us import the numpy in your program as follows:
from numpy import random as np.
Which of the following can be the probable output for the instruction, print(np.randint(100))
A) 56
B) 156
C) 256
D) 356
Question 15: What will be the output of following instructions: print(np.array([[1,2,3],[4,5,6]]).shape)
A) (1,2)
B) (1,2,3)
C) (2,3)
D) (4,5)
Question 16: Given the following code, what will be the output?
    import numpy as np
    arr=np.array([1,2,3,4,5,6,7,8,9])
    print(arr[::3])
A) [1,4,7]
B) [1,2,3]
C) [1,2,3,4,5]
D) [1,3,5,7,9]
Question 17: What is the significance of "continue" statement in a for loop?
A) To exit the loop
B) To skip the remaining code and move to the next iteration
C) To restart the loop from the beginning
D) To print the current iteration and continue
Question 18: What is the output of the following code? print(bool(0), bool(2.15), bool(-5), bool(2.0+1j))
A) True True False True
B) True False False True
C) False True False True
D) False True True True
Question 19: 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:'B', 2:'B', 3:'C'}
B) Method update() doesn't exist for dictionaries
C) {1:'B', 2:'B', 3:'C', 4:'D', 5:'E'}
D) {1:'A', 2:'B', 3:'C', 4:'D', 5:'E'}
Question 20: Kite box in a flow chart is used for _________
A) Connector
B) Decision
C) Statement
D) All of the above
Question 21: Execution of the following python statement will result in open("filename.txt", "w").write("Great Day\n")
A) Error
B) File not closed
C) Writing of file is not performed
D) None of the above
Question 22: What will the following code print? x = [0,1,2,3,4,5] print(x[1:5:2])
A) [1,2,3,4]
B) [1,3]
C) [2,4]
D) Error
Question 23: What is the advantage of Flow chart?
A) Systematic testing
B) Asystematic testing
C) Symmetric testing
D) Improper Communication
Question 24: What will be the output of the following Python code?
        L1 = [2, 4, 6]
        L2 = [-2, -4, -6]
        for i in zip(L1, L2):
            print(i)
A) 2 -2
4, -4
6, -6
B) [(2,-2), (4,-4), (6,-6)]
C) (2, -2)
(4, -4)
(6, -6)
D) [-4, -16, -36]
Question 25: What is the result of the following code?
        lst = [1, 2, 3, 4, 5]
        lst[1:4] = [6, 7, 8]
        print(lst)
A) [1,6,7,8,5]
B) [1,6,7,8]
C) [6,7,8,4,5]
D) IndexError
Question 26: What of the following extension is not a binary file?
A) .py
B) .exe
C) .mp3
D) .jpeg
Question 27: What will be the output of the python code? re.split("mum", "mumbai*", 1)
A) Error
B) ["", "bai*"]
C) ["", "bai"]
D) ['bai*']
Question 28: Which of the following method converts all capital letters of a string into small letters?
A) small()
B) lower()
C) lowercase()
D) smallcase()
Question 29: In file handling, what does this terms means "r, a"?
A) Read, append
B) Append, read
C) Write, append
D) None of the mentioned
Question 30: 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__()
Question 31: Which of the following is the correct way to create a dictionary in Python?
A) {1:"one", 2:"two", 3:"three"}
B) (1:'one', 2:'two', 3:'three')
C) [1:'one', 2:'two', 3:'three']
D) {1,'one', 2,'two', 3,'three'}
Question 32: What does the following symbol shows? O
A) Decision
B) Input
C) Processing
D) Terminal process
Question 33: What will be the output of the following Python code?
        def foo():
            try:
                return 1
            finally:
                return 2
        k = foo()
        print(k)
A) Error, three is more than one return statement in a single try-finally block
B) 3
C) 2
D) 1
Question 34: Which module in python is used for regular expressions?
A) regex
B) re
C) Rex
D) regx
Question 35: To read the remaining lines of the file from a file object infile, which of the following can be used?
A) infile.read(2)
B) infile.read()
C) infile.readline()
D) infile.readlines()
Question 36: What will be the output of the following python code snippet?
        test = {1:'A', 2:'B', 3:'C'}
        del test[1]
        test[1] = 'D'
        del test[2]
        print(len(test))
A) 2
B) 0
C) 1
D) Error as the key-value pair of 1:'A' is already deleted
Question 37: Docstring refers to the ___________
A) String value of a variable of str datatype
B) String literal that occurs as the first statement in a module, function, class, or method definition
C) Documents attached with software
D) None of the above
Question 38: What will be the output of the following python code?
        def f1(a,b=[]):
            b.append(a)
            return b
        print(f1(2,[3,4]))
A) [3,2,4]
B) [3,4,2]
C) [2,3,4]
D) Error
Question 39: What will be the following code output?
        import numpy as np
        arr = np.array([10, 20, 30, 40, 50])
        print(arr[arr > 30])
A) [30, 40, 50]
B) [10, 20]
C) [40, 50]
D) Error: Invalid comparison
Question 40: If A = 0 then GCD(A,B) is __________
A) A
B) B
C) A*A
D) 1
Question 41: What will be the output of the following Python code?
        string="my name is x"
        for i in string.split():
            print(i, end=",")
A) m,y, ,n,a,m,e, ,i,s, ,x,
B) my,name,is,x,
C) m,y, ,n,a,m,e, ,i,s, ,x
D) error
Question 42: What is the output of the following code?
        import numpy as np
        a=np.array([1,2,3])
        b=np.array([4,5,6])
        c=np.stack((a,b))
        print(c)
A) [[1,2,3],[4,5,6]]
B) [[1,4],[2,5],[3,6]]
C) [1,2,3,4,5,6]
D) Error
Question 43: What will be the following output of the following statement: print(3.2**2**3+99/11)
A) 244
B) 244.0
C) -244.0
D) Error
Question 44: Consider the following syntax for file open function Filehandler=open("filename","open mode","buffering") which of the following statement is False?
A) No buffering will be used if 0 is passed as buffering integer
B) 0 as buffering integer is allowed only in text mode
C) 0 as buffering integer is allowed only in binary mode
D) Positive integer as buffering integer implies full buffering
Question 45: What is the result of the following code?
        st=[1,2,3,4,5]
        st[1:4]=[6,7,8]
        print(lst)
A) [1,6,7,8,5]
B) [1,6,7,8]
C) [6,7,8,4,5]
D) NameError
Question 46: 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
Question 47: What will be the output of the following Python function? min(max(False,-3,-4),2,7)
A) -4
B) -3
C) 2
D) False
Question 48: What will be the following code output?
        import numpy as np
        arr=np.array([10,20,30,40,50])
        print(arr[arr>30])
A) [30,40,50]
B) [10,20]
C) [40,50]
D) Error: Invalid comparison
Question 49: Which of the following is the output of the instruction, print(math.log(64,2))
A) 6.0
B) 7.0
C) 2.0
D) 64.0
Question 50: Which of the following functions can delete an element from a list, if it's value is given?
A) pop()
B) remove()
C) del()
D) all of these
Question 51: Observe the following code and identify what will be the outcome?
        import numpy as np
        a=np.array([10,20,30,40])
        b=np.array([18,15,14])
        c=np.array([25,24,26,28,23])
        x,y,z=np.ix_(a,b,c)
        print(x)
A) [[[10]] [[20]] [[30]] [[40]]]
B) [[[1]] [[2]] [[3]] [[4]] [[5]]]
C) Both a and b
D) Error
Question 52: What does the following code print to the console? >>if 88>100:print("cardio")
A) 88
B) cardio
C) 100
D) Nothing is printed
Question 53: Istrip() method is used for
A) Delete all the leading characters
B) Delete all the trailing characters
C) Delete all the leading and trailing characters
D) Delete uppercase characters
Question 54: What will be the output of following Python expression if x=56.236? print("%.2f"%x)
A) 56.236
B) 56.23
C) 56
D) 56.24
Question 55: Which of the following is NOT a sequence data type in Python?
A) String
B) List
C) Dictionary
D) Tuple
Question 56: Recursive function is ___________________.
A) A function that calls itself
B) A function that calls other functions
C) Both
D) None of the above
Question 57: Documentation in software development is important because it__________________.
A) Helps in maintaining the program in the long term
B) Is required by law for all software projects
C) Ensures the program's compatibility with different platforms
D) Replaces the need for testing and debugging
Question 58: What is the result of the following Python expression 5//3**2?
A) 0
B) 1
C) 4
D) Error message
Question 59: What is the output of the following code?
        import numpy as np
        a=np.array([[1,2],[3,4]])
        print(a.ndim)
A) 0
B) 1
C) 2
D) 3
Question 60: Which function is used to return the current file position in bytes?
A) tell()
B) seek()
C) read()
D) write()
Question 61: What is the value returned by math.floor(3.4)?
A) 3
B) 4
C) 3.0
D) 4.0
Question 62: Which operator is used for slicing an ndarray?
A) ,
B) :
C) ;
D) /
Question 63: Which of the following statement display "ARM" two times?
A) >>>"ARM" ++2
B) >>>"ARM" +2
C) >>>"ARM" *2
D) >>>"ARM" **2
Question 64: Algorithm cannot be represented by ________________.
A) pseudo codes
B) syntax
C) flowcharts
D) programs
Question 65: What is NumPy?
A) A programming language
B) A library for numerical computing in Python
C) A data visualization tool
D) A file format for storing data
Question 66: Which of the following is true about function argument in Python?
A) All arguments must have default values
B) Only keyword arguments can be used
C) Only one argument is allowed in a function
D) Arguments are optional can be omitted
Question 67: What is the purpose of the for loop in Python?
A) To define a function
B) To perform conditional execution
C) To iterate over a sequence of items
D) To execute a block of code when a condition is true
Question 68: Which of the following is true about the import statement in Python?
A) It can only import one module at a time
B) It can import multiple modules at a time
C) It can import modules from any directory
D) It can import modules from any programming language
Question 69: How do you define a function in Python?
A) def function_name():
B) function function_name():
C) define function_name():
D) def(): function_name
Question 70: What does the seek() function do in Python?
A) Reads a specified number of characters from a file
B) Moves the file pointer to a specific position
C) Writes a line of text to a file
D) Closes a file
Question 71: ____________ creates an inferior process that runs your program.
A) Run
B) Exit
C) Execute
D) E
Question 72: What will be the output of the following Python code snippet?
        x='abcd'
        for i in range(len(x)):  
            i.upper()
        print(x)
A) a b c d
B) 0 1 2 3
C) error
D) none of the mentioned
Question 73: _________ refers to the ability to make decisions based on criteria conditions.
A) Sequence
B) Selection
C) Iteration
D) None of these
Question 74: Which of the following exceptions is raised if the file already exists when opening it in 'x' mode?
A) FileError
B) IOError
C) FileExistsError
D) None of these
Question 75: What is the purpose of the seek() method in Python file handling?
A) To move the file cursor to a specific position
B) To read the entire contents of a file
C) To write data to a file
D) To close a file
Question 76: Which of the following is the truncation division operator in Python?
A) |
B) //
C) /
D) %
Question 77: Which method is used to format the determine object according to the specified format string in Python?
A) format()
B) strftime()
C) to_string()
D) convert
Question 78: What is the primary purpose of a decision structure in an algorithm or flowchart?
A) To perform mathematical calculations
B) To represent a process or operation
C) To control the flow of execution based on a condition
D) To store and retrieve data
Question 79: What is the value of i after the for loop?, for i in range(4):break
A) 1
B) 2
C) 3
D) 0
Question 80: Observe the following code and identify what will be the outcome?
        import numpy as np
        a=np.array([1,2,3,4,5,6]) 
        print(a)
A) [1 2 3 4 5 6]
B) [1 2 3 4 5]
C) [0 1 2 3 4 5 6]
D) None of the mentioned above
Question 81: Which of the following types of loops are not supported in Python?
A) for
B) while
C) do-while
D) none
Question 82: What will be the output of the following Python code?
        def maximum(x, y): 
            if x>y:
                return x
            elif x==y:
                return 'The numbers are equal'
            else:
                return y
        print(maximum(2, 3))
A) 2
B) 3
C) The numbers are equal
D) None of the mentioned
Question 83: What will be the output of the following Python code?
        def f1(a,b=[]):
            b.append(a)
            return b
        print(f1(2,[3, 4]))
A) [3,2,4]
B) [2,3,4]
C) [3,4,2]
D) Error
Question 84: What will be the following code output?
        import numpy as np
        arr=np.array([10,20,30,40,50])
        print(arr[arr>30])
A) [30,40,50]
B) [10,20]
C) [40,50]
D) Error: Invalid comparison

Report Card

Total Questions Attempted: 0

Correct Answers: 0

Wrong Answers: 0

--