Choice Questions
1.
What is a program in computer science?
- a) A set of machine language
instructions
- b) A collection of hardware components
- c) An ordered set of instructions to be executed
by a computer
- d) A high-level language
- Answer: c) An ordered
set of instructions to be executed by a computer
2.
Which language is called machine
language?
- a) Python
- b) C++
- c) Assembly
- d) 0s and 1s
- Answer: d) 0s and 1s
3.
What is source code?
- a) Machine language code
- b) High-level language code
- c) Assembly language code
- d) Hardware description
- Answer: b) High-level language
code
4.
Which of the following uses an interpreter?
- a) C++
- b) Assembly
- c) Python
- d) Machine language
- Answer: c) Python
5.
Which quote is attributed to Donald Knuth in the textbook?
- a) “Programming is fun.”
- b) “Computer programming is an art.”
- c) “Machines are powerful.”
- d) “High-level languages are easy.”
- Answer: b) “Computer programming is an art.”
6.
Which of the following is NOT a feature of Python?
- a) High-level language
- b) Case-sensitive
- c) Platform-dependent
- d) Rich library of predefined functions
- Answer: c) Platform-dependent
7. What is the symbol for the Python prompt in interactive mode?
- a) $
- b) %
- c) &
- d) »>
- Answer: d) »>
8. What is the extension
of Python source
code files?
- a) .java
- b) .py
- c) .exe
- d) .txt
- Answer: b) .py
9. Which mode in Python
allows the execution of individual statements instantaneously?
- a) Script mode
- b) Interactive mode
- c) Batch mode
- d) Compiled mode
- Answer: b) Interactive mode
10. Which of the following
is a Python keyword?
- a) print
- b) import
- c) function
- d) main
- Answer: b) import
11. Which of the following
is a valid identifier in Python?
- a) 123abc
- b) abc123
- c) a!bc
- d) None of these
- Answer: b) abc123
12. What is a variable
in Python?
- a) A reserved word
- b) A function
- c) An object uniquely
identified by a name
- d) A type of operator
- Answer: c) An object
uniquely identified by a name
13. Which symbol is used for comments
in Python?
- a) //
- b) #
**- c) @**
- d) &
- Answer: b) #
14. In Python, everything is treated as a(n):
- a) Variable
- b) Function
- c) Object
- d) Keyword
- Answer: c) Object
15. Which function
returns the identity
of an object in Python?
- a) id()
- b) identity()
- c) object_id()
- d) get_id()
- Answer: a) id()
16. What are the two execution modes in Python?
- a) Compiled and Interpreted
- b) Interactive and Script
- c) Synchronous and Asynchronous
- d) Batch and Real-time
- Answer: b) Interactive and Script
17. Which of the following is NOT a feature of Python?
- a) Free and open-source
- b) Case-sensitive
- c) Platform-independent
- d) Requires a compiler
- Answer: d) Requires a compiler
18. Which of the following
is NOT a keyword in Python?
- a) while
- b) assert
- c) print
- d) pass
- Answer: c) print
19. What is the output
of the following Python code: ‘print(“Hello, World!”)‘?
- a) Hello, World!
- b) “Hello, World!”
- c) print(“Hello, World!”)
- d) Syntax Error
- Answer: a) Hello, World!
20. Which of the following
statements is true about Python?
- a) Python is a low-level language.
- b) Python is case-sensitive.
- c) Python cannot be used for web development.
- d) Python uses a compiler for execution.
- Answer: b) Python is case-sensitive.
21. What is the correct
syntax for a single-line comment
in Python?
- a) // This is a comment
- b) /* This is a comment
*/
- c) # This is a comment
- d) < This is a comment
>
- Answer: c) # This is a comment
22. Which of the following is NOT a Python data type?
- a) Integer
- b) String
- c) Boolean
- d) Character
- Answer: d) Character
23. How do you create
a variable in Python?
- a) Using the var keyword
- b) By simply assigning
a value to it
- c) Using the let keyword
- d) By declaring it first
- Answer: b) By simply
assigning a value
to it
24. Which of the following is used for indentation in Python?
- a) Curly braces
- b) Parentheses
- c) Tabs or spaces
- d) Semicolons
- Answer: c) Tabs or spaces
25. What will be the output of the following
code: ‘print(2 + 3 * 4)‘?
- a) 20
- b) 14
- c) 24
- d) 12
- Answer: b) 14
26. Which Python function is used to get input from the user?
- a) input()
- b) read()
- c) scanf()
- d) get_input()
- Answer: a) input()
27. What does the following
Python code do: ‘name = input(“Enter your name:”)‘?
- a) Prints “Enter your name:”
- b) Assigns the string
“Enter your name:” to the variable name
- c) Prompts the user to enter their name and stores
it in the variable name
- d) Generates a syntax
error
- Answer: c) Prompts the user to enter their name and stores it in the variable name
28. Which of the following is an invalid
variable name in Python?
- a) var1
- b) _var
- c) 1var
- d) var_1
- Answer: c) 1var
29. What is the output
of the following code: ‘print(10
/ 3)‘?
- a) 3.3333333333333335
- b) 3
- c) 3.0
- d) 10
- Answer: a) 3.3333333333333335
30. Which of the following is NOT an arithmetic operator
in Python?
- a) +
- b) -
- c) *
- d) &&
- Answer: d) &&
31. What is the correct
way to create a string
in Python?
- a) ‘string s = “Hello”‘
- b) ‘s = ‘Hello’‘
- c) ‘s = Hello‘
- d) ‘string s = ‘Hello’‘
- Answer: b) ‘s = ‘Hello’‘
32. Which of the following methods can be used to convert a string to a list in Python?
- a) list()
- b) split()
- c) convert()
- d) str()
- Answer: b) split()
33. Which of the following is NOT a valid Python
data type?
- a) List
- b) Tuple
- c) Dictionary
- d) Array
- Answer: d) Array
34. What is the output
of the following code: ‘print(“Hello” + ” ” + “World”)‘?
- a) Hello World
- b) HelloWorld
- c) “Hello World”
- d) Hello + World
- Answer: a) Hello World
35. Which operator
is used for exponentiation in Python?
- a) ^
- b) **
- c) exp()
- d) pow()
- Answer: b)
36. Which of the following is a mutable
data type in Python?
- a) String
- b) Tuple
- c) List
- d) Integer
- Answer: c) List
37. What is the output
of the following code: ‘print(2**3)‘?
- a) 5
- b) 6
- c) 8
- d) 9
- Answer: c) 8
38. Which function
is used to read input from the user in Python 3.x?
- a) input()
- b) raw_input()
- c) scan()
- d) read()
- Answer: a) input()
39. Which of the following statements will create
a tuple in Python?
- a) t = [1, 2, 3]
- b) t = {1, 2, 3}
- c) t = (1, 2, 3)
- d) t = 1, 2, 3
- Answer: c) t = (1, 2, 3)
40. What is the output
of the following code: ‘print(type([]))‘?
- a) <class ‘tuple’>
- b) <class ‘list’>
- c) <class ‘set’>
- d) <class ‘dict’>
- Answer: b) <class ‘list’>
41. Which of the following
operators is used for string concatenation in Python?
- a) +
- b) &
- c) .
- d) concat()
- Answer: a) +
42. What is the correct
way to declare a variable
in Python?
- a) var x = 5
- b) x := 5
- c) int x = 5
- d) x = 5
- Answer: d) x = 5
43. What will be the output of the following code: ‘print(10 % 3)‘?
- a) 1
- b) 3
- c) 10
- d) 0.3
- Answer: a) 1
44. Which method
is used to remove an item from a list in Python
by its value?
- a) remove()
- b) pop()
- c) delete()
- d) discard()
- Answer: a) remove()
45. What is the output
of the following code: ‘print(5
== 5)‘?
- a) True
- b) False
- c) Syntax Error
- d) 5
- Answer: a) True
46. Which method
can be used to convert
a list into a tuple in Python?
- a) tuple()
- b) list_to_tuple()
- c) to_tuple()
- d) convert()
- Answer: a) tuple()
47. Which of the following is used to define a block of code in Python?
- a) Indentation
- b) Curly braces
- c) Parentheses
- d) Square brackets
- Answer: a) Indentation
48. Which function
is used to get the type of an object
in Python?
- a) type()
- b) isinstance()
- c) id()
- d) obj_type()
- Answer: a) type()
FILL-IN THE BLANK (SAMPLE).**
1. Python is an example of a -level programming language. (high)
2. In Python, strings
are enclosed in or . (single, double)
3. Python’s core data types include , , and . (integers,
floats, strings)
4. are used to document Python functions and modules. (docstrings)
5. Python uses to indicate a block of code. (indentation)
6. are objects in Python that cannot be changed after assignment. (tuples)
2 Marks Questions and Answers
1.
What is a programming language? A programming language is a language used to specify a set of instructions to a computer
to carry out a specific
task.
2.
Define a program.
A program is an ordered
set of instructions to be executed by a computer
to carry out a specific
task.
3.
What is machine language? Machine
language, also known as low-level language, is the language of 0s and 1s that is directly understood by the computer.
4.
What is the difference between high-level language and machine
language? High-level languages are
easier for humans to write and understand, whereas machine language is composed
of binary code (0s and 1s) and is directly understood by the computer.
5. Name any two high-level programming languages. Python and Java.
6. What is source code? Source code is a program
written in a high-level language.
7. What is the role of a
compiler? A compiler translates the entire source
code into machine language as a whole and generates
error messages if any.
8. What is the role of an interpreter? An interpreter processes program statements one by one, translating and executing them until an error is encountered or the program
is successfully executed.
9. Define Python as a high-level
language. Python
is a high-level, interpreted, and case-sensitive program-
ming language known for its readability and simplicity.
10. What does it mean that Python is an interpreted language?
Python being an interpreted language
means that its programs are executed by an interpreter, which processes each statement one by one.
11. How does Python handle case sensitivity? Python is case-sensitive, meaning identifiers like NUMBER and number
would be considered different.
12. Mention any two features
of Python. Python is portable and platform-independent, and it has a rich library of predefined functions.
13. What is the extension
of a Python script file? The extension of a Python script file is .py.
14. Explain the interactive mode in Python.
In interactive mode, individual statements
can be executed instantaneously, and results are displayed immediately.
15. What is script mode in
Python? In script mode, a Python program is written
in a file, saved, and then executed as a whole.
16. What are Python keywords? Python
keywords are reserved words that have specific meanings to the interpreter and cannot be used as identifiers.
17. Define identifiers in Python. Identifiers are names used to identify
variables, functions, or other entities
in a program.
18. What are variables in Python? Variables in Python are names that refer to objects stored in memory.
19. How are comments added in Python?
Comments in Python are added using the # symbol;
everything following the # till the end of the line is treated as a comment.
20. What is an object
in Python? An object
in Python is an instance
of a data type that has a unique identity, attributes, and behavior.
21. What is implicit conversion? Implicit conversion is the automatic
conversion of one data type to another
by the interpreter.
22. What is explicit conversion? Explicit conversion is the manual conversion of one data type to another using functions like int(), float(),
str(), etc.
3 Marks Questions and Answers
1. Explain the process of program execution in Python using
an interpreter.
• Python uses an interpreter to execute programs. The interpreter
processes the program statements one
by one, translating and executing each statement sequentially until an error is
encountered or the entire program is
executed. If an error occurs, execution stops. This contrasts with a compiler, which translates the entire source code into object code before execution .
2. What is the significance of the Python
prompt »>?
• The »> prompt in Python indicates that the interpreter is ready
to accept instructions. This prompt is
displayed in the Python interactive mode, also known as the Python shell, where
users can type commands or statements to be executed
immediately .
3. Describe the use of indentation in Python.
• Indentation in Python is used to define the blocks of code. Unlike
other programming languages that use
braces or keywords, Python relies on indentation levels to group statements. Consistent indentation is crucial
because it directly
affects the program’s
structure and execution
.
4. Explain the concept of ‘interactive mode’ with an example.
• Interactive mode in Python allows users to type and execute Python
commands directly at the »> prompt. This mode is useful for testing and debugging code snippets. For example:
>>> print("Hello, World!") Hello, World!
This command
is executed immediately, and the result is displayed
on the screen .
5.
What are the rules for naming an identifier in Python?
• Identifiers in Python must follow
these rules:
1. Must start with a letter
(a-z, A-Z) or an underscore (_).
2. Can contain letters,
digits (0-9), and underscores.
3. Cannot start with a digit.
4. Python keywords cannot be used as identifiers.
5. Identifiers are case-sensitive .
6. Explain with an example
how variables are declared in Python.
• Variables in Python
are declared by assigning a value to a name. For example:
>>> x = 10
>>> name
= "Alice"
Here, x is an integer variable
with a value of 10, and name is a string variable
with a value of “Alice”
.
7. How does Python handle
data types?
• Python handles data types dynamically,
meaning variables do not need to be declared with a specific type. Python
supports various data types, including integers, floats, strings, lists,
tuples, dictionaries, and sets. The type of a variable
is determined at runtime based
on the value assigned to it .
8.
Describe the purpose
of comments in a Python
program.
• Comments in Python are used to document the code and make it easier
to understand. They are ignored by the interpreter and can be
single-line comments starting with # or multi-line comments enclosed in triple quotes (’’’ or “““). Comments help explain the logic and
purpose of the code, making it easier to maintain and collaborate with others .
9. Explain the significance of the id() function in Python.
• The id() function
in Python returns
the unique identity
(memory address) of an object.
This identity is guaranteed to be unique
and constant for the object
during its lifetime. The id() function
is useful for understanding the object’s behavior
and identity management in memory .
10.
Differentiate between None and False in Python
keywords.
• None is a special constant in Python representing the absence of a
value or a null value. It is often used
to signify that a variable has no value. False, on the other hand, is a Boolean
value indicating the logical false. It is used in logical operations
and comparisons. While None and False are distinct, both can be used in condition checks
where None evaluates to False in a Boolean
context .
11.
What is meant by ‘Python
is platform-independent’?
• Python is considered platform-independent because Python programs can run on various operating
systems without modification. This is possible
because Python code is interpreted, and the Python
interpreter abstracts the underlying platform
details. As long as the system has a compatible Python interpreter installed, the same Python code can run on Windows, macOS, Linux, and other platforms
.
12.
Describe how Python uses indentation for blocks and nested blocks.
• In Python, indentation is used to define the scope of loops,
functions, and other constructs. Con- sistent
indentation levels indicate a block of code. For nested blocks, each new block
is indented further, usually by four spaces. This
indentation helps Python understand the grouping of statements, replacing the need for braces or keywords used in other languages .
13.
Explain the term ‘portable’ in the context
of Python.
• The term ‘portable’ in the context
of Python refers
to the ability to write
Python code that can run on different operating systems and
environments without requiring changes. Python achieves portability through its interpreter, which
handles platform-specific details,
allowing the same code to execute on any system
with a compatible Python interpreter .
14.
What are Python libraries and why are they important?
• Python libraries are collections of modules and packages that
provide pre-written code to perform common tasks. They
are important because they save developers time and effort by offering reusable code for various functionalities, such as
data manipulation, web development, machine learning, and more. Popular Python libraries include NumPy, Pandas,
Matplotlib, and TensorFlow .
15.
Describe how to download and install Python.
•
To download and install
Python:
1. Visit the official
Python website (https://www.python.org/ ).
2. Download the installer for your operating
system.
3. Run the installer and follow the on-screen instructions.
4. Ensure
that the option to add Python to the system PATH is selected.
5. Verify the installation by opening a command prompt
or terminal and typing python
–version .
16. What is meant by ‘Python is free and open source’?
• Python being ‘free
and open source’
means that it is freely
available for anyone
to use, modify,
and distribute. The source code of Python
is openly accessible, allowing developers to contribute to its development and customize it as needed.
This openness fosters a large and active community that continually improves the language and its ecosystem ..