0% found this document useful (0 votes)
7 views8 pages

Python Programming Question Bank

Uploaded by

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

Python Programming Question Bank

Uploaded by

Priyanga G
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON PROGRAMMING-QUESTION BANK

2 marks with Answers

Unit I
1. Define an algorithm
An algorithm is a procedure or formula for solving a problem, based on conducting a Sequence of
specified actions. Algorithm is an ordered sequence of finite, well defined, unambiguous instructions
for completing a task. It is an English-like representation of the logic which is used to solve the
problem. It is a step- by-step procedure for solving a task or a problem. The steps must be ordered,
unambiguous and finite in number. . Write an algorithm to find minimum of 3 numbers in a list.

[Link] : Find Minimum of 3 numbers in a list


Step 1: Start

Step 2: Read the three numbers A, B, C

Step 3: Compare A and B.

If A is minimum, go to step 4 else go to step 5.

Step 4: Compare A and C.

If A is minimum, output “A is minimum” else output “C is minimum”. Go to step 6.

Step 5: Compare B and C.

If B is minimum, output “B is minimum” else output “C is minimum”.

Step 6: Stop

3. Specify any 5 programming languages


Java, C, C++, Python, PHP
4. Distinguish between pseudo code and flowchart
Flowchart is usually a graphical representation, where as pseudo-code is something written
in a language. Note that they both show the step by step procedure for solving a problem. One
is graphical while one is text based.
5. Define recursion
Recursion is the process of defining a problem (or the solution to a problem) in terms of a
Simpler version of itself. A recursive procedure or routine is one that has the ability to call
Itself.
6. Define control flow statement.
A program's control flow is the order in which the program's code executes. The control
flow of a Python program is regulated by conditional statements, loops, and function calls.
7. What is the concept of towers of Hanoi?
The objective of the game is to move the entire stack of disks from Tower 1 to Tower 3.
PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
You can move only one disk at a time. No disk may be placed on top of a smaller disk. With 3
disks, the puzzle can be solved in 7 moves. The minimal number of moves required to solve a
Tower of Hanoi puzzle is 2n − 1, where n is the number of disks.
8. Explain list.
In computer science, a list or sequence is an abstract data type that represents a countable
number of ordered values, where the same value may occur more than once. The name list is
also used for several concrete data structures that can be used to implement abstract lists,
especially linked lists. Many programming languages provide support for list data types, and
have special syntax and semantics for lists and list operations.

9. List the building blocks of an algorithm.


The building blocks of an algorithm are

 Statements

 Sequence

 Selection or Conditional

 Repetition or Control flow

 Functions

10. Define statement. List its types.


Statements are instructions in Python designed as components for algorithmic problem

solving, rather than as one-to-one translations of the underlying machine language instruction

set of the computer.

There are three types of high-level programming language statements Input/output

statements make up one type of statement. An input statement collects a specific value from

the user for a variable within the program. An output statement writes a message or the value

of a program variable to the user’s screen.

11. What is Iteration?


Iteration is the repetition of a process in a computer program, usually done with the help of
loops. Many computer programs and programming languages use iterations to perform
Specific tasks, solve problems, and present solutions.
12. Explain how do you assess problem solving method.
The problem solving method is the process of working through details of a problem to
reach a solution. Problem solving may include mathematical or systematic operations and can
be a gauge of an individual's critical thinking skills. Methods for assessing problem-solving
PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
learning outcomes vary with the nature of the -problem. Problem solving processes are
normally assessed by coding schemes. Based on that assumption, numerous models of
problem solving have been suggested, most of which involve a sequence of steps, including:
• Define the problem.
• Analyze the problem (identify possible causes).
• Investigate the problem (gather information).
• Generate possible solutions.
• Evaluate the alternative solutions.
13. What is meant by sorting? Mention its types
Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way
to arrange data in a particular order. Types of Sorting Techniques
• Bubble Sort.
• Insertion Sort.
• Selection Sort.
• Quick Sort.
• Merge Sort.
• Heap Sort.
14. Define programming language.
A programming language is a vocabulary and set of grammatical rules for instructing a
computer or computing device to perform specific tasks. The term programming language
usually refers to high-level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN,
Ada, and Pascal.
15. Discuss building blocks of algorithm.
Any algorithm can be constructed from just three basic building blocks. These three
building blocks are Sequence, Selection, and Iteration. Sequence is an action in which one or
more instructions that the computer performs in sequential order (from first to last). Selection
is a Decision making choice among several actions. Iteration can be a Loop in which one or
more instructions that the computer performs repeatedly.
16. What are the steps for developing algorithms.
• Problem definition
• Development of a model
• Specification of Algorithm
PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
• Designing an Algorithm
• Checking the correctness of Algorithm
• Analysis of Algorithm
• Implementation of Algorithm
• Program testing
• Documentation Preparation
14. Give an example for recursion function
#To find the factorial of a number
def calc_factorial(x):
if x == 1:
return 1
else:
return (x * calc_factorial(x-1))
num = 4
print("The factorial of", num, "is", calc_factorial(num))
output : The factorial of 4 is 24
17. Discuss building blocks of algorithm.
Any algorithm can be constructed from just three basic building blocks. These three
building blocks are Sequence, Selection, and Iteration. Sequence is an action in which one or
more instructions that the computer performs in sequential order (from first to last). Selection
is a Decision making choice among several actions. Iteration can be a Loop in which one or
more instructions that the computer performs repeatedly.

18. Differentiate predefined function and user defined function.


Predefined functions are part of the programming language. For e.g. built-in C functions, like printf( )
and scanf( ). A user-defined function is a function which the programmer creates and uses in a
program.

. Write the pseudo code to calculate the sum and product of two numbers and display it.
INITIALIZE variables sum, product, number1, number2 of type real

PRINT “Input two numbers”

READ number1, number2

sum = number1 + number2

PRINT “The sum is “, sum

COMPUTE product = number1 * number2


PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
PRINT “The Product is “, product

END program

19. How does flow of control work?


Control flow (or flow of control) is the order in which individual statements, instructions or

function calls of an imperative program are executed or evaluated. A control flow statement is

a statement in which execution results in a choice being made as to which of two or more

paths to follow.

20. What is a function?


Functions are "self-contained" modules of code that accomplish a specific task. Functions

usually "take in" data, process it, and "return" a result. Once a function is written, it can be used

over and over and over again. Functions can be "called" from the inside of other functions.

21. Write the pseudo code to calculate the sum and product displaying the answer on
the monitor screen.
INITIALIZE variables sum, product, number1, number2 of type real

PRINT “Input two numbers”

READ number1, number2

sum = number1 + number2

PRINT “The sum is “, sum

COMPUTE product = number1 * number2

PRINT “The Product is “, product

END program

22. Give the rules for writing Pseudo codes.


Write one statement per line.

Capitalize initial keywords.

Indent to show hierarchy.

End multiline structure.

Keep statements to be language independent.

23. Give the difference between flowchart and pseudo code.


Flowchart and Pseudo code are used to document and represent the algorithm. In other words,

an algorithm can be represented using a flowchart or a pseudo code. Flowchart is a graphical

representation of the algorithm. Pseudo code is a readable, formally styled English like language
PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
representation of the algorithm.

24. Define a flowchart.


A flowchart is a diagrammatic representation of the logic for solving a task. A flowchart is

drawn using boxes of different shapes with lines connecting them to show the flow of control.

The purpose of drawing a flowchart is to make the logic of the program clearer in a visual form.

12. Give an example of iteration.

a=0

for i from 1 to 3 // loop three times

a = a + i // add the current value of i to a

print a // the number 6 is printed (0 + 1; 1 + 2; 3 + 3)

25. Write down the rules for preparing a flowchart.


While drawing a flowchart, some rules need to be followed—

(1) A flowchart should have a start and end,

(2) The direction of flow in a flowchart must be from top to bottom and left to right, and

(3) The relevant symbols must be used while drawing a flowchart.

14. List the categories of Programming languages.

Programming languages are divided into the following categories:

Interpreted, Functional, Compiled, Procedural, Scripting, Markup, Logic-Based, Concurrent

and Object-Oriented Programming Languages

26. Mention the characteristics of an algorithm.


 Algorithm should be precise and unambiguous.

 Instruction in an algorithm should not be repeated infinitely.

 Ensure that the algorithm will ultimately terminate.

 Algorithm should be written in sequence.

 Algorithm should be written in normal English.

 Desired result should be obtained only after the algorithm terminates.

27. Compare machine language, assembly language and high-level language.


Machine language is a collection of binary digits or bits that the computer reads and

Interprets. This language is not easily understandable by the human.


PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers
An assembly language directly controls the physical hardware. A program written in assembly

language consists of a series of instructions mnemonics that correspond to a stream of executable

instructions, when translated by an assembler can be loaded into memory and executed. The

programs written in this language are not portable and the debugging process is also not very

easy.

A high level language is much more abstract, that must be translated or compiled in to

machine language. It is easily understandable and the programs are portable. Debugging the code is
easy

and the program written is not machine dependent.

28. What is the difference between algorithm and pseudo code?


An algorithm is a systematic logical approach used to solve problems in a computer while

pseudo code is the statement in plain English that may be translated later to a programming

language. Pseudo code is the intermediary between algorithm and program.

29. List out the simple steps to develop an algorithm.


Algorithm development process consists of five major steps.

Step 1: Obtain a description of the problem.

Step 2: Analyze the problem.

Step 3: Develop a high-level algorithm.

Step 4: Refine the algorithm by adding more detail.

Step 5: Review the algorithm.


PYTHON PROGRAMMING-QUESTION BANK
2 marks with Answers

You might also like