0% found this document useful (0 votes)
3 views5 pages

Key Programming Concepts Explained

Python notes for exam

Uploaded by

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

Key Programming Concepts Explained

Python notes for exam

Uploaded by

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

2 Marks Questions:

1. Define iterative statements with program.


Definition: Iterative statements, also known as loops, are used to execute a
set of instructions repeatedly until a specified condition is met.

Example:
for i in range(1, 4):
print(i)

[Link] is the use of algorithm, flowchart and pseudocode in the


perspective of problem solving?
Algorithm:
• A set of clear steps to solve a problem.
 Flowchart:

• A diagram that shows the steps of a process using shapes and arrows.
 Pseudocode:

• Writing down the steps of a plan in plain language, mixed with


simple programming terms..(or) Pseudocode is like conveying the
process in plain language.
[Link] between algorithm and program.
Algorithm:
 Definition: An algorithm is a step-by-step plan or set of instructions
to solve a problem.
Program:
 Definition: A programis a set of instructions written in a
programming language that a computer can execute.
[Link] interpreter and compiler. What type of translator is used for
python?

Interpreter:
• Translates and executes code line-by-line.

• Slower, as translation happens during runtime.

• Easier for debugging, as it stops and shows errors immediately.


Compiler:

• Translates the entire code into machine language before execution.

• Faster, as code is already translated.

• Harder for debugging, as all errors are listed after compiling.


Python:

• Uses an interpreter, meaning it translates and executes code line-by-


line, making it easier to test and debug.

[Link] are keywords? Give examples.


Keywords
Definition: Keywords are reserved words in a programming language that
have a predefined meaning and cannot be used for any other purpose, such
as naming variables or functions.
Examples:
 Python Keywords:
 if

 else

 while

 for

 def

 return

[Link] of Iterative Statements in Python


for loop:
Repeats the block of code for each item in a sequence.
Example for loop
for i in range(3):
print(i)
while loop:
Repeats the block of code as long as the condition is true.
Example while loop
i=0
while i < 3:
print(i)
i += 1
7. Assigning a Value to a Tuple in Python
You can't change a value in an existing tuple (it's immutable), but you can
create a new tuple:

Example:
my_tuple = (1, 2, 3)
8. Difference Between List and Tuple
 List: Mutable, can change its elements.
Example:
my_list = [1, 2, 3]
my_list[0] = 4

Output:
[4,2,3]
Tuple:
Immutable, cannot change its elements.
Example:
my_tuple = (1, 2, 3)
my_tuple[0] = 4
Output:
# This will raise an error.
9. Recursion
Recursion is a function calling itself to solve a smaller instance of the
problem.
Example:
def a (n):
if n == 1:
return 1
else:
return n * a(n – 1)
print(a(2))
10. Exit-Controlled Loop vs. Entry-Controlled Loop
 Exit-Controlled Loop:

• Checks the condition at the end


 Entry-Controlled Loop:

• Checks the condition at the beginning ).

You might also like