wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Introduction to Programming and Algorithms

Total questions: 112

Worksheet time: 56mins

Name
Class
Date
1.

Which statement best defines a program in computing?

a)

A list of tasks executed by humans

b)

A sequence of instructions for a computer

c)

A random set of code snippets and files

d)

A visual diagram describing data flows

2.

In the input–processing–output model, which part corresponds to computation on received data?

a)

Input stage performing data entry

b)

Processing stage transforming inputs

c)

Output stage formatting results

d)

Storage stage archiving records

3.

Consider the Python snippet: a = 5; b = 10; sum = a + b; print("The sum is:", sum). What will be displayed?

a)

The sum is: a + b

b)

The sum is: 15

c)

The sum is: 5

d)

The sum is: 10

4.

Which description most accurately defines an algorithm?

a)

A step-by-step finite process

b)

An infinite sequence of trial steps

c)

A casual guideline without rules

d)

A diagram illustrating hardware

5.

Which characteristic ensures an algorithm does not run forever?

a)

Finiteness guaranteeing termination

b)

Effectiveness using basic operations

c)

Definiteness with unambiguous steps

d)

Generality allowing many problems

6.

Which statement reflects definiteness in a good algorithm?

a)

Steps are unambiguous and precise

b)

Steps require advanced hardware

c)

Steps are optional and flexible

d)

Steps vary by user intuition

7.

Given an array A = [7, 3, 9] and x = 3, what index will linear search return? Assume zero-based indexing.

a)

Return -1 because 3 is absent

b)

Return 0 after first comparison

c)

Return 1 when match is found

d)

Return 2 after checking all

8.

During linear search, what should be returned if the end of the array is reached without finding x?

a)

Return the array length

b)

Return the last index checked

c)

Return -1 indicating not found

d)

Return None to halt program

9.

Which statement best defines a data structure in programming?

a)

A tool for compiling Python programs

b)

A protocol for network data transfer

c)

A way of organizing data in memory

d)

A method to format code comments neatly

10.

Which list contains only linear data structures?

a)

Dictionary, Set, Hash Table

b)

Tree, Graph, Heap, Trie

c)

Matrix, Tensor, Vector Space

d)

Array, Linked List, Stack, Queue

11.

Which category describes data arranged hierarchically with parent-child relationships?

a)

Non-linear structures arranged hierarchically

b)

Hash-based structures using key-value

c)

Relational tables with SQL joins

d)

Linear structures arranged sequentially

12.

In Python, which data structure is the closest example of hash-based storage?

a)

Tuple storing immutable sequences

b)

List storing elements by index

c)

Dictionary storing key–value pairs

d)

Array storing contiguous integers

13.

You need fast lookups of student details by roll number. Which structure fits best?

a)

Dictionary mapping roll to details

b)

Queue of incoming students

c)

Array with sequential roll numbers

d)

Linked list of student nodes

14.

Which scenario most benefits from non-linear data structures like graphs?

a)

Processing ordered tasks in a queue

b)

Storing contiguous sensor readings

c)

Maintaining a fixed-size circular buffer

d)

Modeling social network connections

15.

A dataset grows from thousands to millions of entries. What property ensures the system remains responsive?

a)

Portability across operating systems

b)

Scalability handling large datasets

c)

Interactivity of the user interface

d)

Redundancy of backup copies

16.

For searching a value, which option correctly compares time complexities?

a)

Unsorted linear search O(n), binary search O(log n)

b)

Unsorted linear search O(log n), binary search O(n)

c)

Binary search and hash lookup are both O(n)

d)

Both unsorted and binary search are O(1)

17.

Which statement best describes dynamic typing in Python?

a)

Type inferred from function

b)

Type decided at runtime

c)

Type chosen by the interpreter once

d)

Type fixed by variable name

e)

Type decided at compile time

18.

Given x = 10, which data type does x have?

a)

str

b)

complex

c)

int

d)

bool

e)

float

19.

Which collection is unordered in Python?

a)

list

b)

range

c)

tuple

d)

string

e)

set

20.

Select the correct example of a tuple literal.

a)

{"a": 1}

b)

{1, 2, 3}

c)

(10)

d)

(10, 20)

e)

[1, 2, 3]

21.

What do control flow statements primarily determine in a program?

a)

Memory allocation strategy

b)

Order in which code executes

c)

Names of variables used

d)

Data types of expressions

e)

Compilation optimization level

22.

In Python’s normal execution without control flow, code runs in which manner?

a)

Randomly by interpreter choice

b)

Bottom to top in files

c)

Line by line, top to bottom

d)

Function by function only

e)

Statement groups by modules

23.

Which statement executes a block only when a condition is True?

a)

elif

b)

for

c)

while

d)

if

e)

else

24.

Given x = -3, which output matches the code: if x > 0: print("Positive number")

a)

No output produced

b)

True printed

c)

Negative number

d)

Positive number

e)

Error at runtime

25.

Which option lists only numeric data types in Python?

a)

float, str, complex

b)

complex, tuple, int

c)

int, bool, float

d)

int, float, complex

e)

int, list, float

26.

Choose the correct literal for a dictionary with keys name and age.

a)

{"John": "name", 25: "age"}

b)

{"name": "John", "age": 25}

c)

["name", "John", 25]

d)

("name", "John", 25)

e)

{"name", "John", "age", 25}

27.

Which statement best explains the role of boolean expressions in conditionals?

a)

They create new variables

b)

They store text values

c)

They define numeric ranges

d)

They evaluate to True or False

e)

They sort collections automatically

28.

You need a collection with unique items and no order. Which type fits best?

a)

set for uniqueness only

b)

dict for key-value pairs

c)

tuple for immutability

d)

list for flexible order

e)

string for sequence text

29.

Which statement best describes a Python for loop?

a)

Runs until memory is exhausted automatically

b)

Evaluates a condition and returns True or False

c)

Iterates over each element in a sequence

d)

Executes code once without repetition

30.

What does range(5) produce when used in a for loop like for i in range(5): print(i)?

a)

Numbers 0 through 4 inclusive

b)

Even numbers 0 to 8 inclusive

c)

A single integer equal to 5

d)

Numbers 1 through 5 inclusive

31.

Which Python construct repeats a block while a condition remains True?

a)

match statement in Python 3.10

b)

def function with parameters

c)

while loop with Boolean condition

d)

for loop over a dictionary

32.

Choose the correct output of the code: s = 'abc'; for ch in s: print(ch)

a)

a then b then c on new lines

b)

a b c on one line

c)

abc on one line

d)

Nothing because strings are not iterable

33.

In a while loop, where should the update to the loop variable typically occur?

a)

Only in the loop condition itself

b)

Outside the loop before entering

c)

Inside the loop body after condition check

d)

Nowhere; Python updates it automatically

34.

Identify the bug causing an infinite loop: i = 0; while i < 3: print(i)

a)

The condition uses less-than incorrectly

b)

Missing increment of i in the loop

c)

print cannot be used in while loops

d)

range should be used instead of while

35.

Which statement correctly iterates over a list nums = [2,4,6]?

a)

for n in nums: print(n)

b)

for i in range(nums): print(i)

c)

for index in 0..len(nums): print(index)

d)

while nums: print(nums[0])

36.

Select the best reason to use a for loop over a while loop.

a)

When the iteration count is unknown

b)

When preventing syntax errors in code

c)

When iterating directly over a sequence

d)

When needing complex conditional logic

37.

What is the final value printed by for i in range(5): print(i)?

a)

4

b)

0

c)

5

d)

None

38.

Which condition correctly stops a while loop that accumulates until total >= 100?

a)

while total == 100:

b)

while total < 100:

c)

while total >= 100:

d)

while total > 100:

39.

Given nums = [1,3,5,7], what does the loop do? sum = 0; for x in nums: sum += x; print(sum)

a)

Prints 4 because list length

b)

Prints 16 after summing all values

c)

Prints 7 because last element only

d)

Raises TypeError for addition

40.

Which statement best avoids off-by-one errors when iterating indices of a list L?

a)

for i in range(1, len(L))

b)

for i in range(0, len(L)+1)

c)

for i in range(0, len(L))

d)

for i in range(1, len(L)+1)

41.

Which Python jump statement exits a loop immediately when triggered?

a)

pass

b)

stop

c)

continue

d)

break

42.

In a for loop, what does continue do when a condition is met?

a)

Repeats same iteration

b)

Jumps two iterations

c)

Skips current iteration

d)

Ends the loop now

43.

Which statement is used as a placeholder that does nothing when executed?

a)

pass

b)

idle

c)

noop

d)

halt

44.

Consider: for i in range(10): if i == 5: break; print(i). What is the last value printed?

a)

5

b)

4

c)

6

d)

9

45.

Given: for i in range(5): if i == 2: continue; print(i). Which single value is omitted from output?

a)

4

b)

1

c)

0

d)

2

46.

Which best describes the loop else clause in Python?

a)

Runs only when break occurs

b)

Runs after normal completion

c)

Runs when loop starts

d)

Runs before each iteration

47.

When does the else block on a loop NOT execute?

a)

When the loop body is empty

b)

When continue is used

c)

When range is zero

d)

When break exits the loop

48.

Choose the correct effect of pass inside a loop body.

a)

Restarts loop from top

b)

Does nothing and continues

c)

Skips printing output

d)

Terminates loop early

49.

You need to ignore a specific value while scanning a list but keep looping. Which statement is appropriate?

a)

break

b)

stop

c)

return

d)

continue

50.

A while loop decrements count by 1 until count > 0. What ensures termination?

a)

A pass statement

b)

The else clause always

c)

A break in the header

d)

The decreasing state

51.

Which output matches: for i in range(5): if i == 2: continue; print(i)

a)

0 2 3 4

b)

0 1 3 4

c)

1 2 3 4 5

d)

0 1 2 3 4

52.

Plan a robust search loop that stops when a target is found and reports if not found. Which construct pairing is most suitable?

a)

continue with pass

b)

return with continue

c)

break with loop else

d)

pass with loop else

53.

Which statement best defines a function in Python?

a)

A block of reusable code for a task

b)

A single variable storing program state

c)

A loop construct for repeated steps

d)

A comment explaining program logic

54.

Which example best matches the function analogy of a coffee machine?

a)

Input, processing, and output flow

b)

Class inheritance and polymorphism

c)

Thread scheduling and synchronization

d)

File I/O buffering and caching

55.

Which advantage of functions directly relates to writing code once and using it many times?

a)

Abstraction of hardware calls

b)

Code reusability across modules

c)

Readability of variable names

d)

Modularity of data types

56.

Which advantage primarily makes code easier to understand for humans?

a)

Abstraction using APIs

b)

Modularity via packages

c)

Maintainability with logs

d)

Readability through structure

57.

Which advantage helps break a program into small, logical parts?

a)

Maintainability tools

b)

Abstraction of logic

c)

Modularity with functions

d)

Reusability of blocks

58.

Which advantage means you don’t need to know internal logic, only how to call it?

a)

Abstraction of implementation

b)

Reusability via libraries

c)

Readability through comments

d)

Maintainability with testing

59.

Which built-in behavior does the pass statement represent in Python loops?

a)

An immediate loop termination

b)

A placeholder that does nothing

c)

A pause until user input

d)

A counter increment operation

60.

In a for loop with an else clause, when does the else block execute?

a)

Never in Python’s for loops

b)

Always after each iteration

c)

Only when loop encounters continue

d)

Only if loop finishes without break

61.

Given the code: for i in range(3): print(i) else: print("Loop completed"), what is the final output line?

a)

Loop completed after 0,1,2

b)

Break encountered at i==2

c)

Pass prevents final message

d)

Continue skips printing 2

62.

Which benefit of functions most directly supports easier debugging and updates?

a)

Modularity in design

b)

Reusability of code

c)

Abstraction of details

d)

Maintainability over time

63.

Choose the best reason to wrap repeated logic inside a function.

a)

Reuse, readability, and maintainability

b)

Faster CPU clock speed

c)

Automatic memory garbage collection

d)

Lower network latency

64.

You’re designing a program with repeated data-cleaning steps. Which approach aligns with modularity and reusability?

a)

Define a clean() function and call it

b)

Copy-paste the cleaning code blocks

c)

Write cleaning inside a while loop

d)

Store steps in global variables

65.

Which keyword starts the definition of a user-defined function in Python?

a)

def keyword begins a function

b)

func keyword declares functions

c)

lambda keyword defines functions

d)

return keyword starts functions

66.

What is the primary purpose of a docstring inside a Python function?

a)

Describe the function behavior

b)

Import external libraries

c)

Execute the function logic

d)

Store temporary variables

67.

Given def greet(name): return f"Hello, {name}!", what does print(greet("Alice")) output?

a)

Hello, Alice!

b)

Alice says hello

c)

Hi there, Alice

d)

Hello, {name}!

68.

Which statement best describes a lambda function in Python?

a)

Anonymous function defined with lambda

b)

Module-level function imported from math

c)

Class method requiring self parameter

d)

Named function created using def

69.

What is a common use case for lambda functions?

a)

Short, throwaway operations

b)

Persistent configuration files

c)

Long, stateful procedures

d)

Complex class hierarchies

70.

Consider square = lambda x: x*x. What is print(square(5))?

a)

25

b)

10

c)

125

d)

5

71.

Which built-in function returns the number of items in a list?

a)

range() counts items

b)

len() counts items

c)

sum() counts items

d)

type() counts items

72.

For nums = [1, 2, 3, 4], what does sum(nums) return?

a)

4 total value

b)

9 total value

c)

10 total value

d)

6 total value

73.

Which line correctly places an optional docstring in a function?

a)

// Explains the function

b)

# Explains the function

c)

'''Executed by Python'''

d)

"""Explains the function"""

74.

Which statement about recursion is accurate?

a)

Function must avoid any parameters

b)

Function loops without any calls

c)

Function always uses global variables

d)

Function calls itself with base case

75.

In a recursive factorial function, what is the typical base case for n?

a)

n equals 0 or 1

b)

n equals any prime

c)

n equals 2 only

d)

n equals negative one

76.

Which code snippet best exemplifies defining and returning a value from a user-defined function?

a)

def add(): print(a+b) only

b)

lambda add: a+b then return

c)

class add(): return method

d)

def add(a,b): return a+b

77.

Which statement best describes positional arguments in a Python function call?

a)

Their order determines parameter mapping

b)

They require keyword syntax in calls

c)

Their names determine parameter mapping

d)

They must have default values defined

78.

Given def add(a, b): return a + b, what does print(add(10, 5)) output?

a)

an error due to types

b)

a tuple (10, 5)

c)

'15' as string literal

d)

15 as integer value

79.

Which function call correctly uses keyword arguments for greet(name, msg)?

a)

greet(name="Alice", msg="Hello")

b)

greet("Hello", "Alice")

c)

greet(msg name="Alice")

d)

greet(msg: "Hello", name: "Alice")

80.

In def greet(name, msg="Hello"): print(f"{msg}, {name}"), what is printed by greet("Bob")?

a)

Hello, Bob

b)

Good Morning, Bob

c)

Bob, Hello

d)

None is printed

81.

Which choice correctly explains *args in a function definition?

a)

Collects extra positional arguments

b)

Creates local-only variables

c)

Collects extra keyword arguments

d)

Defines default parameter values

82.

Which choice correctly explains **kwargs in a function definition?

a)

Collects extra keyword arguments

b)

Collects extra positional arguments

c)

Specifies return type annotation

d)

Forces positional-only parameters

83.

Which statement about local scope is accurate in Python functions?

a)

Variables defined inside a function are local

b)

Local variables persist after function returns

c)

Local variables are accessible from other modules

d)

Local scope equals global module namespace

84.

Which keyword allows a function to modify a module-level variable?

a)

return

b)

nonlocal

c)

global

d)

yield

85.

Which keyword lets an inner function rebind a variable from an enclosing function scope?

a)

nonlocal

b)

global

c)

extern

d)

static

86.

What does a Python return statement do inside a function?

a)

Pauses execution like yield

b)

Declares a global constant

c)

Prints a value to the console

d)

Sends a value back to the caller

87.

Which is valid when a function needs to return multiple values to callers?

a)

Mutate caller variables implicitly

b)

Return a tuple of values

c)

Use multiple return keywords

d)

Return values via print calls

88.

In the recursive factorial example, which condition prevents infinite recursion?

a)

Base case if n == 0

b)

Using keyword arguments

c)

Returning multiple values

d)

Defining default parameters

89.

Which statement best describes Object-Oriented Programming in Python?

a)

Uses objects only for storing global variables

b)

Organizes code around objects and their interactions

c)

Focuses only on functions and linear logic flow

d)

Runs faster than procedural programming by default

90.

In OOP, what are attributes of an object?

a)

Steps of a procedural algorithm

b)

Data describing the object's state

c)

Reusable blocks of executable behavior

d)

External libraries imported into classes

91.

Which term refers to behaviors an object can perform?

a)

Procedures of the object

b)

Attributes of the object

c)

Methods of the object

d)

Modules of the object

92.

Python supports which programming paradigms?

a)

Event-driven paradigm only

b)

Procedural and object-oriented paradigms

c)

Functional and declarative paradigms

d)

Only object-oriented paradigm

93.

Which option correctly pairs car properties with OOP concepts?

a)

Start(), stop() are attributes; color is a method

b)

Brand, color, speed are attributes; start() is a method

c)

Speed is a method; accelerate() is an attribute

d)

Brand is a method; accelerate() is an attribute

94.

Which is a primary advantage of OOP for large Python projects?

a)

Improves modularity through class-based design

b)

Eliminates the need for testing entirely

c)

Replaces functions with global variables

d)

Guarantees faster runtime in all cases

95.

What does reusability mean in the context of OOP?

a)

Objects run without any dependencies

b)

Global variables persist between modules

c)

Classes and methods can be used across programs

d)

Each function must be written only once

96.

Which statement best contrasts OOP with procedural programming?

a)

OOP uses inheritance; procedural uses recursion

b)

OOP organizes around objects; procedural organizes around functions

c)

OOP forbids functions; procedural forbids objects

d)

OOP is only for GUIs; procedural is only for scripts

97.

Which benefit of OOP most directly supports long-term code changes?

a)

Higher network throughput

b)

Built-in database persistence

c)

Maintainability through clear structure

d)

Automatic parallel execution

98.

A student designs a Car class with speed and color, and methods start() and stop(). What principle is being applied?

a)

Encapsulation of data and behavior

b)

Recursion within procedural code

c)

Compilation into machine language

d)

Global state management

99.

Which example best illustrates abstraction in OOP?

a)

Using print statements to debug low-level details

b)

Writing a long procedural script without functions

c)

Storing all settings in global variables for easy access

d)

Providing a start() method without exposing engine complexity

100.

You are refactoring a large project into classes. Which outcome aligns with OOP advantages?

a)

All code converts to functional style

b)

Global variables automatically disappear

c)

Execution time always decreases significantly

d)

Modules become easier to test and reuse

101.

In Python OOP, what best describes a class?

a)

Module that contains global code

b)

Template defining object structure

c)

Runtime copy of an instance

d)

Function for initializing attributes

102.

What is an object in Python OOP?

a)

Global variable shared by all

b)

Special method like __init__

c)

Blueprint for many instances

d)

Instance created from a class

103.

Which statement about the __init__ method is correct?

a)

Automatically runs when an object is created

b)

Defines class variables only by default

c)

Manually called after object creation

d)

Returns the newly constructed class

104.

Given class Car with def __init__(self, brand, model): self.brand=brand; self.model=model. What does print(c1.brand) output for c1=Car("Tesla","Model X")?

a)

brand

b)

Model X

c)

Car

d)

Tesla

105.

Which benefit of OOP refers to dividing code into smaller parts like classes?

a)

Abstraction

b)

Modularity

c)

Maintainability

d)

Scalability

106.

Which OOP benefit best matches "easier to debug and update"?

a)

Scalability

b)

Abstraction

c)

Reusability

d)

Maintainability

107.

In class Student with __init__(self,name,roll): self.name=name; self.roll=roll, what is s.name for s=Student("Alice",101)?

a)

Student

b)

name

c)

101

d)

Alice

108.

What distinguishes instance variables from class variables?

a)

Class variables exist only in __init__

b)

Instance variables belong to objects

c)

Class variables stored per object instance

d)

Instance variables shared across all objects

109.

Which term refers to hiding implementation details in OOP?

a)

Abstraction

b)

Modularity

c)

Reusability

d)

Scalability

110.

If c2=Car("BMW","i8"), what does print(c2.model) display?

a)

Car

b)

model

c)

BMW

d)

i8

111.

Which option best explains reusability in OOP?

a)

Classes and objects used across programs

b)

Constructors eliminate duplicated functions

c)

Objects created only once per runtime

d)

Methods copy code between modules

112.

Which OOP advantage makes the approach suitable for large projects?

a)

Scalability

b)

Reusability

c)

Modularity

d)

Abstraction