0% found this document useful (0 votes)
68 views28 pages

MCQ 1

The document contains a series of fill-in-the-blank, true/false, matching, code correction, output prediction, and theory questions related to Python programming. It covers topics such as functions, variable naming, data types, control flow, and syntax errors. The questions are designed to test knowledge and understanding of Python programming concepts.

Uploaded by

globalsadan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views28 pages

MCQ 1

The document contains a series of fill-in-the-blank, true/false, matching, code correction, output prediction, and theory questions related to Python programming. It covers topics such as functions, variable naming, data types, control flow, and syntax errors. The questions are designed to test knowledge and understanding of Python programming concepts.

Uploaded by

globalsadan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Fill in the Blanks:

_____ function is used to display output in Python.

a) print()

b) printf()

c) display()

d) show()

To take user input in Python, we use the ________ function.

a) scanf()

b) input()

c) scan()

d) read()

The format string %d is used for printing ________.

a) integer

b) float

c) string

d) char

In Python, variable names are ________.

a) case sensitive

b) case insensitive

c) lowercase

d) uppercase

In Python, the function used to print output to the console is ________.


a) print()

b) display()

c) show()

d) output()

To receive user input in Python, the function used is ________.

a) get_input()

b) input()

c) user_input()

d) receive_input()

The following expression evaluates to ________: 5 / 2

a) 2.5

b) 2

c) 2

d) 2.25

________ is the correct syntax for declaring a variable in Python.

a) variable_name = value

b) value = variable_name

c) value variable_name

d) variable_name : value

____________ operator is used for exponentiation in Python.

a) ^

b) **

c) *

d) //
All keywords in Python are in __________

a) Capitalized

b) lower case

c) UPPER CASE

d) None of the mentioned

The _____ keyword is used to define an indefinite loop in Python.

a) while

b) for loop

c) if-else

d) break

The _____ statement is used to skip the current iteration and continue with the next iteration
of the loop.

a) jump

b) continue

c) go-to

d) break

The _____ function is used to iterate over a sequence of numbers.

a) map

b) arange

c) reduce

d) range
True or False:

Python has a built-in function called type that can be used to check the type of a variable.

a) True

b) False

Python supports dynamic typing, meaning you can reassign a variable to a value of a different
type.

a) True

b) False

Variable names in Python can start with a number.

a) True

b) False

The format string %s is used for printing integers.

a) True

b) False

In Python, the if statement can be used without the else statement.

a) True

b) False

Python supports the use of the switch statement for multiple conditional branches.

a) True

b) False
Python allows the use of the elseif keyword for branching in conditional statements.

a) True

b) False

Python's conditional statements can only check for equality and cannot perform other types of
comparisons.

a) True

b) False

True/False: The print() function in Python is used to read input from the user.

a) FALSE

b) TRUE

True/False: The input() function in Python is used to display output to the console.

a) FALSE

b) TRUE

True/False: Identifiers in Python are used to name variables, functions, classes, and other
objects.

a) FALSE

b) TRUE

True/False: Python lists are ordered collections of items where each item has an associated key.

a) FALSE

b) TRUE

True/False: Python comparison operators like <, >, ==, != are used to perform arithmetic
operations.

a) FALSE
b) TRUE

The for loop is ideal when you know the exact number of iterations needed.

a) True

b) False

The else block in a loop is executed if the loop completes without encountering a break
statement.

a) True

b) False

A while loop is suitable for iterating over the elements of a list.

a) True

b) False

The range() function returns a list of integers.

a) True

b) False
Match the Following:
Match the following:

column A column B

a. if 1. Loop through a sequence

b. for 2.Define a function

c. def 3.Make a decision

d. while 4.Repeat a block of code

a) "a-3, b-4, c-1, d-2"

b) "a-3, b-1, c-2, d-4"

c) "a-2, b-1, c-4, d-3"

d) "a-1, b-2, c-3, d-4"

Match the following:

column A column B

a. int 1.[1,2,3,4]

b. str 2.""colluge""

c. list 3. {1:"start",2:"end",3:"continue"}

d. dict 4. 34

a) "a-3, b-1, c-2, d-4"

b) "a-2, b-1, c-4, d-3"

c) "a-1, b-2, c-3, d-4"

d) "a-4, b-2, c-1, d-3"

Match the following:

column A column B

a. == 1. Less than

b. != 2. Not equal to
c. > 3. Equal to

d. < 4. Greater than

a) "a-4, b-2, c-1, d-3"

b) "a-4, b-1, c-2, d-3"

c) "a-3, b-2, c-4, d-1"

d) "a-4, b-3, c-1, d-2"

Match the following:

column A column B

a. + 1. Subtraction

b. - 2. Multiplication

c. * 3. Addition

d. / 4. Division

a) "a-3, b-1, c-2, d-4"

b) "a-1, b-3, c-4, d-2"

c) "a-1, b-2, c-3, d-4"

d) "a-4, b-3, c-2, d-1"

Match the following:

column A column B

a. \n 1. Tab

b. \t 2. Newline

c. \r 3. Carriage return (move cursor to start)

d. \b 4. Backspace

a) "a-2, b-1, c-3, d-4"

b) "a-1, b-3, c-4, d-2"

c) "a-4, b-1, c-2, d-3"

d) "a-2, b-3, c-4, d-1"


Correct the Code:
What is wrong with the following code snippet?

x = input("Enter a number: ")

print("The square of the number is: ", x * x)

A) The input function is missing an argument

B) The input function returns a string, so x * x won't work for multiplication

C) The print function is missing a comma after the string

D) There is nothing wrong with the code

What correction should be made to the following code to print the result of adding two numbers
entered by the user?

num1 = input('Enter the first number: ')

num2 = input('Enter the second number: ')

print(num1 + num2)

A) Convert num1 and num2 to integers using int() before adding them

B) Use eval() function to evaluate the sum

C) Use int(input()) instead of input() for num1 and num2

D) All of the above

How would you correct the code to print the formatted string "The price is $50.00"?

price = 50.00

print("The price is $" + price)

A) Convert price to a string before concatenation using str()

B) Use f-string formatting like print(f"The price is ${price:.2f}")

C) Change print statement to print("The price is $", price)

D) A,B and C
What correction is needed to store a boolean value in the variable is_true in the code below?

is_true = input('Enter True or False: ')

A) Use eval(input()) for is_true

B) Convert the input to a boolean using is_true = bool(input())

C) Use input(bool()) for is_true

D) There is no need for correction; the code is correct as it is

What correction is needed to store the binary value in the variable num?

Num = 110101

a. Num = 0b110101

b. Num = 0o110101

c. Num = 0x110101

d. Num = 0X110101

Rectify the errors:

def factorial(n):

if n == 0:

return 1

else:

return n * factorial(n-1)

num = 5

print("Factorial of", num, "is", factorial(num))

Rectify the errors:

def count_vowels(string):

vowels = 'aeiou'

count = 0

for char in string.lower():

if char in vowels:
count += 1

return count

Rectify the errors:

Copy code

def is_palindrome(string):

return string == string[-1::-1]

word = "radar"

Rectify the errors:

python

Copy code

def calculate_average(numbers):

total = 0

count = 0

for num in numbers:

total += num

count += 1

average = total / count

return average

nums = [10, 20, 30, 40, 50]

result = calculate_average(nums)

print("The average is: ", result)

print("Hello", "World!")

a) Hello World!

b) Hello World
c) Hello, World

d) Syntax Error

Identify the error in the following code:

count = 0

while count < 5:

print(count)

count += 1

A) Missing colon after while count < 5

B) Incorrect indentation for the count += 1 statement

C) Missing parentheses in while statement

D) No error

Identify the error in the following code:

numbers = [1, 2, 3, 4, 5]

for i in numbers:

print(i)

else

print("Done")

A) Missing colon after else

B) Missing indentation for the print("Done") statement

C) Missing parentheses in for statement

D) No error

Identify the error in the following code:

for i in range(5):

if i == 3:
print("Found")

A) Missing colon after for i in range(5)

B) Missing indentation for the if i == 3: statement

C) Missing parentheses in range function

D) No error
Predict the Output:
What will be the output of the following code snippet?

x = 10

y = "20"

z = x + int(y)

print(z)

a)30

b)’30’

c)10+20

D)error

What will be the output of the following code?

x=5

y = 10

print("The sum of " + str(x) + " and " + str(y) + " is " + str(x + y))

a)The sum of 5 and 10 is 15

b)TheSumof5and8is15

c)TheSumof’5’and’8’is’15’

d)15

What is the output of the following code?

x = "Hello"

y=3

print(x * y)

a)Hello Hello Hello

b)HelloHelloHello

c)error
d)Hello

The output of which of the codes shown below will be: “There are 4 blue birds.”?

a) ‘There are %g %d birds.’ %4 %blue

b) ‘There are %d %s birds.’ %(4, blue)

c) ‘There are %s %d birds.’ %[4, blue]

d) ‘There are %d %s birds.’ 4, blue

What will be the output of the Python code shown below for various styles of format specifiers?

x=1234

res='integers:...%d...%-6d...%06d' %(x, x, x)

print(res)

x = 5 y = 2 print(x * y)

a) 5

b) 10

c) 15

d) 20

x = 10 // 2 print(x)

a) 5

b) 5

c) "5"

d) Syntax Error

x = 10 // 2 print(x * 2)

a) 10

b) 5
c) 25

d) Error

x = 5 y = "10" print(x + y)

a) 15

b) Error

c) "15"

d) Syntax Error

What will be the output of the following Python code?

s='{0}, {1}, and {2}'

s.format('hello', 'good', 'morning')

What is the output of below snippet?

x=2

if x == 1: print('foo'); print('bar'); print('baz')

elif x == 2: print('qux'); print('quux')

else: print('corge'); print('grault')

a) foo

bar

baz

b) qux

quux

c) corge

grault

d) None of the above

What is the output if age is 21?


age = int(input("Please enter your age: "))

if age < 18:

print("You need to be over 18 years old to continue")

elif age < 21:

print("You need to be over 21 years old")

else:

print("You are over 18 and 21 so you can continue")

a) You need to be over 18 years old to continue

b) You need to be over 21 years old

c) You are over 18 and 21 so you can continue

d) None of the above

What is the output of below code snippet?

'yes' if ('qux' in ['foo', 'bar', 'baz']) else 'no'

a) yes

b) no

c) foo

d) False

What is the output of below code snippet?

name = 'JOE'

if name == 'Fred':

print('Hello Fred')

elif name == 'Xander':

print('Hello Xander')

elif name == 'Joe':


print('Hello Joe')

elif name == 'Arnold':

print('Hello Arnold')

else:

print("I don't know who you are!")

a) Hello Fred

b) Hello Xander

c) Hello Joe

d) I don't know who you are!


THEORY:
Which is the correct operator for power(xy)?

a) X^y

b) X**y

c) X^^y

d) None of the mentioned

Who developed the Python language?

a) Zim Den

b) Guido van Rossum

c) Niene Stom

d) Wick van Rossum

In which language is Python written?

a) C++

b) Java

c) C

d) PHP

Which one of the following is the correct extension of the Python file?

a) .py

b) .python

c) .p

d) None of these

What do we use to define a block of code in Python language?

a) Key
b) Brackets

c) Indentation

d) None of these

Which of the following declarations is incorrect?

a) _x = 2

b) __x = 3

c) xyz = 5

d) None of these

What is the purpose of conditional statements in Python?

a) To execute code sequentially

b) To repeat code multiple times

c) To make decisions based on certain conditions

d) To define functions and classes

What is the role of the elif keyword in Python's conditional statements?

a) It introduces a new condition to be checked if the previous condition is true

b) It defines the start of a new conditional block

c) It terminates the conditional statement

d) It defines a loop iteration in the conditional block

In Python, what is the significance of proper indentation in conditional statements?

a) It has no effect on the execution of the code

b) It determines the order of conditions to be checked

c) It specifies the scope of the code blocks

d) It is required for defining variables within the conditional block


What happens if none of the conditions in a series of if-elif-else statements evaluate to true?

a) The program crashes

b) The else block is executed

c) The program skips the conditional statements entirely

d) The elif block is executed

Which operator is used for logical NOT operation in Python's conditional statements?

a) &&

b) ||

c) and

d) not

What is the purpose of the else keyword in Python's conditional statements?

a) It introduces a new condition to be checked if the previous condition is true.

b) It defines the start of a new conditional block.

c) It executes a block of code if none of the previous conditions were true.

d) It terminates the conditional statement.

Which keyword is used to check multiple conditions sequentially after an initial if statement?

a) else

b) elif

c) or

d) and

What happens if none of the conditions in a series of if-elif-else statements are true?

a) The program crashes

b) The else block is executed


c) The program skips the conditional statements entirely

d) The program waits indefinitely

Which operator is used for inequality comparison in Python's conditional statements?

a) =

b) ==

c) !=

d) >

What keyword is used to check multiple conditions sequentially after an initial if statement?

a) else

b) elif

c) or

d) and

What is the purpose of the not operator in Python's conditional statements?

a) It checks if two values are equal

b) It checks if a value is not equal to another value

c) It negates the value of the following expression

d) It performs logical OR operation

Which operator is used for equality comparison in Python's conditional statements?

a) =

b) ==

c) ===

d) !=

What happens if none of the conditions in a series of if-elif-else statements are true?
a) The program crashes

b) The else block is executed

c) The program skips the conditional statements entirely

d) The program waits indefinitely

Which operator is used for inequality comparison in Python's conditional statements?

a) =

b) ==

c) !=

d) >

What keyword is used to check multiple conditions sequentially after an initial if statement?

a) else

b) elif

c) or

d) and

What is the purpose of the not operator in Python's conditional statements?

a) It checks if two values are equal

b) It checks if a value is not equal to another value

c) It negates the value of the following expression

d) It performs logical OR operation

Which operator is used for logical AND operation in Python's conditional statements?

a) &&

b) ||

c) and

d) or
What happens if the elif keyword is omitted from a series of if-elif-else statements in Python?

a) The program crashes

b) The else block is executed

c) The program skips the conditional statements entirely

d) None of the above

In Python, the or operator in conditional statements requires:

a) Both conditions to be true for the overall expression to be true

b) Either of the conditions to be true for the overall expression to be true

c) Both conditions to be false for the overall expression to be true

d) None of the above

Which operator is used for logical AND operation in Python's conditional statements?

a) &&

b) ||

c) and

d) or

What happens if the elif keyword is omitted from a series of if-elif-else statements in Python?

a) The program crashes

b) The else block is executed

c) The program skips the conditional statements entirely

d) None of the above

In Python, the or operator in conditional statements requires:


a) Both conditions to be true for the overall expression to be true

b) Either of the conditions to be true for the overall expression to be true

c) Both conditions to be false for the overall expression to be true

d) None of the above

Which of the following statements about short-circuit evaluation in Python's conditional


statements is true?

a) It evaluates all conditions in a conditional statement regardless of the result.

b) It stops evaluating conditions as soon as the overall result is determined.

c) It only evaluates the first condition in a conditional statement.

d) It reverses the logical outcome of a condition.

What is the purpose of the range() function in Python loops?

a) To generate a sequence of numbers that can be iterated over

b) To check the condition for continuing or breaking the loop

c) To calculate the sum of all elements in a list or tuple

d) To skip the current iteration and move to the next iteration

Which of the following is true about the pass statement in Python?

a) It is used to skip the current iteration of a loop.

b) It is used to terminate a loop.

c) It is used as a placeholder when a statement is required syntactically but you do not want any
command or code to execute.

d) None of the above.

What does the else block in a loop do in Python?

a) It is executed if the loop encounters a break statement


b) It is executed after the loop completes normally (without encountering a break)

c) It is executed before the loop starts

d) It is executed if the loop encounters an exception

What does the range function in Python return?

a) A list of numbers

b) A generator object that produces numbers

c) A tuple of numbers

d) An iterator object that produces numbers

Which data type is used to store a sequence of characters in Python?

a) Integer

b) String

c) Float

d) Boolean

Which of the following correctly describes the purpose of the print() function in Python?

a) To read input from the user

b) To perform mathematical operations

c) To display output to the console

d) To define a function

In Python, what does the input() function do?

a) Prints output to the console

b) Reads input from the user

c) Performs mathematical calculations


d) Defines a loop

What is the purpose of using identifiers in Python?

a) To store numeric values

b) To perform string operations

c) To name variables, functions, etc.

d) To execute loops

Which of the following correctly describes a data type in Python

a) A set of predefined functions

b) A collection of values

c) A file that stores data

d) A loop in the code

You might also like