EXAM QUESTIONS COMPUTER PROGRAMMING I
1. What is the purpose of a programming language?
a) To communicate with computers
b) To write books
c) To draw pictures
d) To play games
2. Which of the following is a high-level programming language?
a) Assembly language
b) C++
c) Machine language
d) Binary code
3. What is a variable in programming?
a) A constant value
b) A storage location with a specific name and type
c) A mathematical operation
d) A function that returns a value
4. What is the main function of a compiler?
a) To convert source code to machine code
b) To debug code
c) To execute code
d) To store data
5. Which data type is used to store whole numbers in programming?
a) Float
b) String
c) Integer
d) Double
6. What does the "if" statement do in programming?
a) Executes a block of code only if a condition is true
b) Loops through a block of code
c) Exits a loop
d) Executes a block of code repeatedly
7. What is a loop in programming?
a) A conditional statement
b) A data structure
c) A way to repeat a block of code
d) A variable type
8. Which operator is used for equality comparison in programming?
a) ==
b) ++
c) /
d) *
9. What is the purpose of comments in code?
a) To confuse other programmers
b) To explain the code to humans
c) To execute specific lines of code
d) To hide code from execution
10. Which of the following is NOT a programming paradigm?
a) Procedural
b) Object-Oriented
c) Functional
d) Arithmetic
11. What does the acronym IDE stand for?
a) Integrated Development Environment
b) Intelligent Design Engine
c) In-Depth Examination
d) International Data Exchange
12. What is the output of the following code snippet?
a) 8
b) 15
c) 53
d) Error
13. Which keyword is used to define a function in Python?
a) def
b) function
c) define
d) func
14. What is the purpose of the "return" statement in a function?
a) To exit the function
b) To print a value
c) To return a value from the function
d) To comment out code
15. Which of the following is a valid way to comment in Python?
a) // This is a comment
b) /* This is a comment */
c) # This is a comment
d) <!-- This is a comment -->
16. What is the output of the following code snippet?
a) Hello
b) World
c) ,
d) Error
17. What is a list in Python?
a) A data type that stores key-value pairs
b) A collection of ordered elements
c) A mathematical function
d) A loop construct
18. What is the purpose of indentation in Python?
a) To make the code look pretty
b) To increase the file size
c) To indicate blocks of code
d) To confuse other programmers
19. Which of the following is NOT a valid variable name in Python?
a) my_variable
b) 123variable
c) _variable
d) variable123
20. What does the "not" operator do in Python?
a) Checks for inequality
b) Negates a boolean value
c) Concatenates strings
d) Raises an error
21. What is the purpose of a constructor in object-oriented programming?
a) To destruct an object
b) To initialize an object's state
c) To copy an object
d) To print an object's attributes
22. Which keyword is used to inherit a class in Python?
a) extends
b) inherits
c) superclass
d) class
23. What does the "self" keyword represent in Python?
a) The class itself
b) The instance of the class
c) A method
d) A variable type
24. What is an exception in programming?
a) An error that occurs during program execution
b) A conditional statement
c) A loop construct
d) A type of data
25. What is the purpose of the "try-except" block in Python?
a) To define a function
b) To handle exceptions
c) To create a loop
d) To print a value
26. Which of the following is NOT a built-in data type in Python?
a) List
b) String
c) Tuple
d) Stack
27. What does the "import" statement do in Python?
a) Imports a module or package
b) Prints a message
c) Defines a function
d) Loops through a block of code
28. What is the output of the following code snippet?
a) 01234
b) 12345
c) 54321
d) Error
29. What does the "append" method do in Python lists?
a) Removes an element from the list
b) Adds an element to the end of the list
c) Reverses the list
d) Sorts the list
30. What is the purpose of the "len" function in Python?
a) To check if an element is in a list
b) To get the length of a list
c) To add elements to a list
d) To remove elements from a list
31. What is the output of the following code snippet?
a) 1
b) 2
c) 3
d) 4
32. What is a dictionary in Python?
a) A collection of ordered elements
b) A data type that stores key-value pairs
c) A loop construct
d) A mathematical function
33. What is the purpose of the "keys" method in Python dictionaries?
a) To get the values from the dictionary
b) To add keys to the dictionary
c) To remove keys from the dictionary
d) To get the keys from the dictionary
34. What does the "pass" statement do in Python?
a) Prints a message
b) Skips execution of code
c) Terminates the program
d) Raises an error
35. What is the purpose of the "break" statement in loops?
a) Continues to the next iteration of the loop
b) Exits the loop
c) Skips a specific iteration of the loop
d) None of the above
36. What is a module in Python?
a) A function that returns a value
b) A collection of functions and variables
c) A loop construct
d) A data type
37. Which of the following is true about tuples in Python?
a) Tuples are mutable
b) Tuples are ordered collections
c) Tuples can be modified after creation
d) Tuples use curly braces {}
38. What does the "in" keyword do in Python?
a) Checks if an element is in a list or tuple
b) Assigns a value to a variable
c) Performs arithmetic operations
d) Defines a function
39. What is the purpose of the "strip" method in Python strings?
a) Removes all characters from a string
b) Removes leading and trailing whitespace
c) Splits a string into a list
d) Converts a string to uppercase
40. What is the output of the following code snippet?
a) ['Hello', 'World!']
b) 'Hello, World!'
c) Hello World
d) Error
41. What does the "format" method do in Python strings?
a) Formats a string as uppercase
b) Formats a string with placeholders
c) Converts a string to a number
d) Splits a string into parts
42. What is the purpose of the "random" module in Python?
a) To perform random arithmetic operations
b) To generate random numbers and values
c) To sort lists randomly
d) To encrypt data
43. What is the output of the following code snippet?
a) A random number between 1 and 10
b) Error
c) 0
d) 1
44. What is a set in Python?
a) A collection of ordered elements
b) A mathematical set
c) A loop construct
d) A data type that stores unique elements
45. What does the "union" method do in Python sets?
a) Combines two sets into one
b) Finds the intersection of two sets
c) Removes elements from a set
d) Checks if a set is a subset of another set
46. What is the purpose of the "intersection" method in Python sets?
a) Combines two sets into one
b) Finds the intersection of two sets
c) Removes elements from a set
d) Checks if a set is a subset of another set
47. What is the difference between "append" and "extend" methods in Python lists?
a) There is no difference
b) "append" adds one element while "extend" adds multiple elements
c) "extend" adds one element while "append" adds multiple elements
d) "append" and "extend" are not valid methods for lists
48. What does the "sort" method do in Python lists?
a) Reverses the list
b) Sorts the list in ascending order
c) Sorts the list in descending order
d) Randomizes the order of elements
49. What is a lambda function in Python?
a) A function with a predefined name
b) An anonymous function
c) A function that returns multiple values
d) A built-in Python function
50. What is recursion in programming?
a) A loop construct
b) A way to define a function
c) A function that calls itself
d) A way to exit a function
51. Which keyword is used for loops in Python?
a) for
b) loop
c) repeat
d) do
52. What does the "range" function do in Python?
a) Creates a list of numbers within a specified range
b) Reverses a list
c) Converts a list to a tuple
d) Checks if a number is in a list
53. What is the purpose of the "map" function in Python?
a) To create a map of locations
b) To apply a function to every item in an iterable
c) To generate random numbers
d) To find the maximum value in a list
54. What is a generator in Python?
a) A function that generates random numbers
b) A way to iterate over a sequence
c) A function that returns a generator object
d) A data structure
55. What does the "yield" keyword do in Python generators?
a) Exits the generator
b) Returns a value from the generator
c) Pauses the generator and yields control back to the caller
d) Raises an error
56. What is the purpose of the "zip" function in Python?
a) To zip files together
b) To create a compressed archive
c) To combine multiple iterables into a single iterable
d) To extract files from a zip archive
57. What is a file object in Python?
a) A data type
b) A module
c) An iterator
d) A way to interact with files
58. Which mode is used to open a file for reading in Python?
a) read
b) write
c) append
d) binary
59. What is the purpose of the "with" statement when working with files in Python?
a) To open a file
b) To close a file
c) To handle file operations safely and automatically close the file
d) To read file contents
60. What is the output of the following code snippet?
a) Error
b) Hello, World!
c) myfile.txt
d) None
ANSWERS
a) To communicate with computers
b) C++
b) A storage location with a specific name and type
a) To convert source code to machine code
c) Integer
a) Executes a block of code only if a condition is true
c) A way to repeat a block of code
a) ==
b) To explain the code to humans
d) Arithmetic
a) Integrated Development Environment
a) 8
a) def
c) To return a value from the function
c) # This is a comment
b) World
b) A collection of ordered elements
c) To indicate blocks of code
b) 123variable
b) Negates a boolean value
b) To initialize an object's state
a) extends
b) The instance of the class
a) An error that occurs during program execution
b) To handle exceptions
d) Stack
a) Imports a module or package
a) 0 1 2 3 4
b) Adds an element to the end of the list
b) To get the length of a list
c) 3
b) A data type that stores key-value pairs
d) To get the keys from the dictionary
b) Skips execution of code
b) Exits the loop
b) A collection of functions and variables
b) Tuples are ordered collections
a) Checks if an element is in a list or tuple
b) Removes leading and trailing whitespace
a) ['Hello', 'World!']
b) Formats a string with placeholders
b) To generate random numbers and values
a) A random number between 1 and 10
d) A data type that stores unique elements
a) Combines two sets into one
b) Finds the intersection of two sets
b) "append" adds one element while "extend" adds multiple elements
b) Sorts the list in ascending order
b) An anonymous function
c) A function that calls itself
a) for
a) Creates a list of numbers within a specified range
b) To apply a function to every item in an iterable
c) A function that returns a generator object
c) Pauses the generator and yields control back to the caller
c) To combine multiple iterables into a single iterable
d) A way to interact with files
a) read
c) To handle file operations safely and automatically close the file
d) None