python test 1
python test 1
10 What is the use of algorithm ? Flowchart and Pseudo code in the perspective of problem
solving (Nov/Dec 2019)
i. Simple to understand
ii. Easy to debug
iii. Independent of programming language
iv. Each step can be easy to written in high-level language.
11 What are the factors used to judge the quality of an algorithm ? (Nov/Dec 2020)
I. Accuracy
II. Memory
III. Time
IV. Sequence
V. Result
12 What is control flow? List and define the ways of execution of control. (Nov/Dec 2020)
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.
i. Sequential control flow
ii. Selection control flow
iii. Iterative control flow
13 List the building blocks of algorithm?
The building blocks of an algorithm are
Statements
Sequence
Selection or Conditional
Repetition or Control flow
Functions
14. 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.
15 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 representation of the algorithm.
PART-B
1 i. Define flow chart? Draw flowchart and write an algorithm to accept three
distinct numbers and find the greatest, print the result (Nov/Dec 2022)
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.
FLOECHART:
ALGORITHM:
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
ii. Outline the algorithm to display the first n odd numbers(Apr/May 2019)
2 I. Draw a flowchart AND algorithm to find the sum of the series 1+2+3…..
+100 (Nov/Dec 2022)
II.What is an algorithm? Summarize the characteristics of a good algorithm.
(Apr/May 2019)
I. FLOWCHART
ALGORITHM:
Read n value as 100.
declare k variable.
Uss formula n*(n+1)/2 to get sum of first 100 natural numbers and hold it in the
variable k.
print k.
II. ALGORITHM:
CHARECTERISTICS:
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.
3 What is a programming language ? What are its types ? Explain in detail with
their advantages and disadvantages (Nov/Dec 2019)
• A programming language is a set of symbols and rules for instructing a computer
to perform specific tasks.
• The programmers have to follow all the specified rules before writing program
using programming language.
• The user has to communicate with the computer using language which it can
understand
1. Machine language
2. Assembly language
3. High level language
MACHINE LANGUAGE:
The computer can understand only 0’s and 1’s.
• In machine language the different instructions are formed by taking different
combinations of 0’s and 1’s.
Advantages:
Translation free:
• For executing any program written in any programming language, the conversion
to machine language is necessary.
• The conversion process is not required.
High speed
• The machine language program is translation free.
• Conversion time is saved
the execution of machine language program is extremely fast
Disadvantage:
• It is hard to find errors in a program written in the machine language.
• Writhing program in machine language is a time consuming process.
Machine dependent:
• According to architecture used, the computer differs from each other.
• Machine language differs from computer to computer.
• Program developed for a particular type of computer may not run on other type
of computer.
ASSEMBLY LANGUAGE:
• To overcome the issues in programming language and make the programming
process easier, an assembly language is developed which is logically
equivalent to machine language but it is easier for people to read, write and
understand.
• Assembly languages are symbolic programming language that uses symbolic
notation to represent machine language instructions.
• They are called low level language because they are so closely related to the
machines.
ASSEMBLER
Assembler is the program which translates assembly language instruction in to a
machine language.
• Easy to understand and use.
• It is easy to locate and correct errors.
Disadvantage
1. Machine dependent
The assembly language program which can be executed on the machine depends
on the architecture of that computer.
2. Hard to learn
It is machine dependent, so the programmer should have the hardware
knowledge to create applications using assembly language.
3. Less efficient
Execution time of assembly language program is more than machine language
program.
Because assembler is needed to convert from assembly language to machine
language.
HIGH LEVEL LANGUAGE
High level language contains English words and symbols.
The specified rules are to be followed while writing program in high level
language.
The interpreter or compilers are used for converting these programs in to
machine readable form.
Translating high level language to machine language
Compiler:
• A compiler is a program which translates the source code written in a high level
language in to object code which is in machine language program.
• Compiler reads the whole program written in high level language and translates
it to machine language.
• If any error is found it display error message on the screen.
Interpreter
• Interpreter translates the high level language program in line by line manner.
• The interpreter translates a high level language statement in a source program to
a machine code and executes it immediately before translating the next
statement.
• When an error is found the execution of the program is halted and error message
is displayed on the screen.
Advantages
Readability
• High level language is closer to natural language so they are easier to learn and
understand
Machine independent
• High level language program have the advantage of being portable between
machines.
Easy debugging
• Easy to find and correct error in high level language
Disadvantages
Less efficient
• The translation process increases the execution time of the program. Programs
in high level language require more memory and take more execution time to
execute.
They are divided into following categories:
Interpreted programming languages
• Functional programming languages
• Compiled programming languages
• Procedural programming languages
• Scripting programming language
• Markup programming language
• Concurrent programming language
• Object oriented programming language
4 Outline the algorithm, flowchart and pseudocode to display the first n odd
numbers(Apr/May 2019)
ALGORITHM:
Step 1: Start
Step 5: Stop
FLOWCHART:
PSEUDOCODE:
1. INPUT n.
2. remainder = n % 2.
3. IF remainder is not equal to 0.
4. answer = odd.
5. ELSE.
6. answer = even.
7. OUTPUT answer.
Example:
Add two numbers:
Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
Selection:
A selection statement causes the program control to be transferred to a specific part of
the program based upon the condition.
If the conditional test is true, one part of the program will be executed, otherwise it will
execute the other part of the program.
Example
Write an algorithm to check whether he is eligible to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
Iteration:
In some programs, certain set of statements are executed again and again based upon
conditional test. i.e. executed more than one time. This type of execution is called
looping or iteration.
Example
Functions:
Def add(a,b):
Sum=a+b
Return sum
Num1=10
Num2=20
Print(‘the sum is’,add(num1,num2))
6 Draw flowchart to print the first n prime numbers(Apr/May 2017)
IS THIS NUMBER PRIME: