Friday, 7 February 2025

MCQs Of Day 1: Introduction to Python Programming


  MCQs Of Day 1
 Introduction to Python Programming

Part 1: General Python Basics

1.   Which of the following is true about Python?

o    a) Python is compiled.

o    b) Python is interpreted.

o    c) Python is both compiled and interpreted.

o    d) Python is neither compiled nor interpreted.
Answer: b) Python is interpreted.
Explanation: Python executes code line-by-line using an interpreter, making it easier to debug and test.

2.   Who developed Python?

o    a) Dennis Ritchie

o    b) Guido van Rossum

o    c) James Gosling

o    d) Bjarne Stroustrup
Answer: b) Guido van Rossum
Explanation: Guido van Rossum developed Python in 1991 to simplify programming.

3.   Which symbol is used for comments in Python?

o    a) //

o    b) /* */

o    c) #

o    d) <!-- -->
Answer: c) #
Explanation: In Python, # is used for single-line comments.

4.   What is the correct extension for Python files?

o    a) .py

o    b) .python

o    c) .pyt

o    d) .txt
Answer: a) .py
Explanation: Python source files are saved with the .py extension.

5.   How do you print text in Python?

o    a) printf("Hello")

o    b) echo "Hello"

o    c) System.out.println("Hello")

o    d) print("Hello")
Answer: d) print("Hello")
Explanation: Python uses the print() function to display output.


Part 2: Installation and Setup

6.   Which website is used to download Python?

o    a) www.python.com

o    b) www.python.org

o    c) www.python.net

o    d) www.installpython.org
Answer: b)
www.python.org
Explanation: Python's official website is
www.python.org.

7.   What option should you select during installation to run Python from any directory?

o    a) Install Now

o    b) Add Python to PATH

o    c) Customize Installation

o    d) Python Interpreter
Answer: b) Add Python to PATH
Explanation: Adding Python to PATH allows running Python commands from the terminal.

8.   How do you check the Python version installed on your system?

o    a) python --version

o    b) python -v

o    c) checkpython

o    d) version python
Answer: a) python --version
Explanation: This command displays the installed Python version.


Part 3: Variables and Data Types

9.   Which of the following is a valid variable name in Python?

o    a) 1name

o    b) name!

o    c) _name

o    d) my-name
Answer: c) _name
Explanation: Variables in Python must start with a letter or underscore and cannot contain special characters like ! or -.

10.                     What data type does the following represent?

x = "Hello, World!"

o    a) int

o    b) str

o    c) bool

o    d) float
Answer: b) str
Explanation: Strings (str) are sequences of characters enclosed in quotes.

11.                     What is the result of 10 + 5 in Python?

o    a) 105

o    b) 15

o    c) "10 + 5"

o    d) Error
Answer: b) 15
Explanation: The + operator adds two integers in Python.


Part 4: Input and Output

12.                     Which function is used to get input from the user?

o    a) input()

o    b) read()

o    c) scanf()

o    d) input_text()
Answer: a) input()
Explanation: The input() function allows user input during program execution.

13.                     What will be the output of the following code?

name = input("Enter your name: ")

print("Hello, " + name)

o    a) Syntax error

o    b) Hello, name

o    c) Hello, (user’s name)

o    d) Enter your name: Hello
Answer: c) Hello, (user’s name)
Explanation: The program concatenates the user input with "Hello, ".


Part 5: Strings

14.                     What does the following code output?

print("Python" + "Programming")

o    a) Python Programming

o    b) PythonProgramming

o    c) Error

o    d) None
Answer: b) PythonProgramming
Explanation: The + operator concatenates strings without adding spaces.

15.                     How do you include a newline in a Python string?

o    a) \n

o    b) \t

o    c) \n

o    d) newline()
Answer: a) \n
Explanation: The \n escape character adds a newline in strings.


Part 6: Errors and Debugging

16.                     What type of error will the following code produce?

print("Hello, World!)

o    a) SyntaxError

o    b) NameError

o    c) TypeError

o    d) ValueError
Answer: a) SyntaxError
Explanation: The missing closing quote causes a SyntaxError.

17.                     How can you run a Python script file named script.py from the terminal?

o    a) execute script.py

o    b) python script.py

o    c) run script.py

o    d) start script.py
Answer: b) python script.py
Explanation: The python command executes Python scripts from the terminal.


Part 7: Python Features

18.Which of the following makes Python beginner-friendly?

o    a) Complex syntax

o    b) Extensive libraries

o    c) High-level language

o    d) Both b and c
Answer: d) Both b and c
Explanation: Python is beginner-friendly due to its simple syntax and extensive libraries.

19.What type of language is Python?

o    a) Low-level

o    b) Assembly

o    c) High-level

o    d) Machine
Answer: c) High-level
Explanation: High-level languages like Python abstract away hardware details.


Part 8: Miscellaneous

20.  Which of the following is NOT a feature of Python?

o    a) Interpreted

o    b) Platform-independent

o    c) Case-sensitive

o    d) Requires compilation
Answer: d) Requires compilation
Explanation: Python does not require compilation; it is an interpreted language.

21.  What is the output of print(3 * "Hi")?

o    a) HiHiHi

o    b) Hi3

o    c) 3Hi

o    d) Error
Answer: a) HiHiHi
Explanation: The * operator repeats strings in Python.


Part 9: Arithmetic and Logical Operators

22.                     What will the result of the following operation be?

10 % 3

o    a) 1

o    b) 3

o    c) 10

o    d) 0
Answer: a) 1
Explanation: The % operator calculates the remainder when 10 is divided by 3.

23.                     What is the output of the following code?

print(2 ** 3)

o    a) 6

o    b) 8

o    c) 9

o    d) 16
Answer: b) 8
Explanation: The ** operator is used for exponentiation (2^3 = 8).

24.                     Which operator is used for logical AND in Python?

o    a) &&

o    b) AND

o    c) and

o    d) &
Answer: c) and
Explanation: The keyword and is used for logical AND operations in Python.


Part 10: Data Types

25.                     What is the output of the following code?

type(5.0)

o    a) int

o    b) float

o    c) double

o    d) decimal
Answer: b) float
Explanation: Numbers with a decimal point in Python are of type float.

26.                     Which of the following is a mutable data type in Python?

o    a) str

o    b) list

o    c) tuple

o    d) int
Answer: b) list
Explanation: Lists are mutable, meaning they can be modified after creation.

27.                     Which of the following is not a valid Python data type?

o    a) str

o    b) char

o    c) list

o    d) bool
Answer: b) char
Explanation: Python does not have a char type; single characters are strings of length 1.


Part 11: String Manipulation

28.                     What will the following code output?

print(len("Python"))

o    a) 6

o    b) 5

o    c) 7

o    d) Error
Answer: a) 6
Explanation: The len() function returns the number of characters in the string, including spaces.

29.                     Which of the following methods converts a string to uppercase?

o    a) upper()

o    b) toUpperCase()

o    c) UPPERCASE()

o    d) uppercase()
Answer: a) upper()
Explanation: The upper() method converts all characters in a string to uppercase.

30.                     What does the following code output?

"Python".lower()

o    a) PYTHON

o    b) python

o    c) Python

o    d) Error
Answer: b) python
Explanation: The lower() method converts all characters to lowercase.


Part 12: Comments and Documentation

31.                     Which type of comment is used in Python?

o    a) Single-line comment using #

o    b) Multi-line comment using """ or '''

o    c) Both a and b

o    d) None of the above
Answer: c) Both a and b
Explanation: Python supports single-line comments (#) and multi-line comments (""" or ''').

32.                     What happens when the following code runs?

# print("Hello, World!")

o    a) Hello, World!

o    b) Nothing

o    c) Error

o    d) None of the above
Answer: b) Nothing
Explanation: Comments are ignored during program execution.


Part 13: Python Features

33.                     What does it mean that Python is dynamically typed?

o    a) You must declare variable types before using them.

o    b) Variable types are checked at runtime.

o    c) Variable types cannot change.

o    d) Python has no data types.
Answer: b) Variable types are checked at runtime.
Explanation: In Python, variables can hold different types of data without explicit type declaration.

34.   Which of the following features make Python platform-independent?

o    a) It compiles to binary code.

o    b) Python programs can run on any operating system with a compatible interpreter.

o    c) It uses the JVM.

o    d) None of the above.
Answer: b) Python programs can run on any operating system with a compatible interpreter.
Explanation: Python's interpreter abstracts away platform differences.


Part 14: Python Scripts

35.                     What will happen if you omit the .py extension while saving a Python file?

o    a) The file won't execute.

o    b) It will execute, but with a warning.

o    c) It can still run if you use the correct command.

o    d) None of the above.
Answer: c) It can still run if you use the correct command.
Explanation: While .py is the standard extension, files without it can still execute using the interpreter.

36.Which command is used to execute a Python script?

o    a) python file_name.py

o    b) run file_name.py

o    c) execute file_name.py

o    d) None of the above
Answer: a) python file_name.py
Explanation: Python scripts are executed using the python command followed by the filename.


Part 15: Advanced Topics (Light)

37.                     What will the following code output?

print("Python", "Programming", sep="-")

o    a) Python Programming

o    b) Python-Programming

o    c) PythonProgramming

o    d) Error
Answer: b) Python-Programming
Explanation: The sep parameter specifies the separator between values.

38.What is the default value of the end parameter in the print() function?

o    a) A space

o    b) A newline (\n)

o    c) A tab (\t)

o    d) None of the above
Answer: b) A newline (\n)
Explanation: By default, print() ends with a newline.


Part 16: Input and Type Conversion

39.What will the output be if a user enters 5 for the following code?

num = input("Enter a number: ")

print(type(num))

o    a) <class 'int'>

o    b) <class 'float'>

o    c) <class 'str'>

o    d) <class 'bool'>
Answer: c) <class 'str'>
Explanation: The input() function always returns user input as a string.

40. How do you convert a string num to an integer in Python?

o    a) int(num)

o    b) float(num)

o    c) str(num)

o    d) num.toInt()
Answer: a) int(num)
Explanation: The int() function converts strings containing numeric data into integers.


Part 17: Python Syntax and Rules

41.Which of the following is the correct way to start a function in Python?

o    a) def function_name():

o    b) function function_name():

o    c) define function_name():

o    d) fun function_name():
Answer: a) def function_name():
Explanation: Python uses the def keyword to define a function.

42.                     What is the correct indentation level in Python?

o    a) 2 spaces

o    b) 4 spaces

o    c) Tabs or spaces, but consistent

o    d) Indentation is not required
Answer: c) Tabs or spaces, but consistent
Explanation: Python enforces indentation, and consistency is key for the code to run correctly.

43.  What does the following code print?

print("Python") 

print("Programming") 

o    a) PythonProgramming

o    b) Python Programming

o    c) Python (on one line) and Programming (on the next line)

o    d) Error
Answer: c) Python (on one line) and Programming (on the next line)
Explanation: By default, print() outputs text on a new line.


Part 18: Variables and Assignments

44.Which of the following is NOT a valid variable name in Python?

o    a) my_var

o    b) 1_variable

o    c) variable_1

o    d) _myvar
Answer: b) 1_variable
Explanation: Variable names cannot start with numbers in Python.

45.  What will the following code print?

x = 10 

x = "Hello" 

print(x) 

o    a) 10

o    b) Hello

o    c) Error

o    d) None of the above
Answer: b) Hello
Explanation: Python variables can change types dynamically; x is reassigned to "Hello."


Part 19: Type Checking and Conversion

46.    What does the following code output?

print(type(True)) 

o    a) <class 'bool'>

o    b) <class 'str'>

o    c) <class 'int'>

o    d) Error
Answer: a) <class 'bool'>
Explanation: The value True is of the Boolean data type (bool).

47.  What happens if you try to add a string and an integer in Python?

o    a) The string is converted to an integer

o    b) The integer is converted to a string

o    c) An error occurs

o    d) None of the above
Answer: c) An error occurs
Explanation: Python does not implicitly convert between strings and numbers for arithmetic operations.


Part 20: Python Comments

48. What is the purpose of comments in Python code?

o    a) To execute optional code

o    b) To include explanatory notes in the code

o    c) To make the code faster

o    d) None of the above
Answer: b) To include explanatory notes in the code
Explanation: Comments are ignored by the Python interpreter and help improve code readability.

49.What is the output of the following code?

# This is a comment 

print("Hello, World!") 

o    a) This is a comment

o    b) Hello, World!

o    c) Error

o    d) None of the above
Answer: b) Hello, World!
Explanation: Comments are ignored, so only the print() statement is executed.


Part 21: Python Input

50. What will the following code do if the user inputs "25"?

age = input("Enter your age: ") 

print(type(age)) 

o    a) Print <class 'int'>

o    b) Print <class 'str'>

o    c) Print <class 'float'>

o    d) Error
Answer: b) Print <class 'str'>
Explanation: The input() function always returns a string, even if the user enters a numeric value.



No comments:

Post a Comment

Search This Blog

Powered by Blogger.

Popular

Name*


Message*