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

Python 2marks

python questions

Uploaded by

mkeerthikacse
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)
3 views4 pages

Python 2marks

python questions

Uploaded by

mkeerthikacse
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 2marks

1) List out the merits of top-down approach


Clear Program Structure
Better Readability
Improved Modularity
Easy Debugging
Simplifies Complex Problems
Better Maintenance
Encourages Code Reusability
Efficient Testing (Unit Testing Friendly)

2) explain the working of compiler and an interpreter


Both compiler and interpreter are language translators.
They convert high-level programming language into machine code so that the computer can execute
it.
Compiler
A compiler translates the entire source program at once into machine code before execution.
Interpreter
An interpreter translates and executes the program line by line.

3)describe the concepts of flowchart and algorithm with suitable examples

Algorithm (2 Marks)
An algorithm is a step-by-step procedure to solve a problem in a finite number of steps.
Example:
1. Start
2. Input A and B
3. Sum = A + B
4. Display Sum
5. Stop
Flowchart (2 Marks)
A flowchart is a graphical representation of an algorithm using standard symbols like oval
(Start/Stop), rectangle (Process), diamond (Decision), and parallelogram (Input/Output).
Example:
Start → Input A, B → Sum = A + B → Display Sum → Stop

4)define the time complexity factors of an algorithm


Time complexity is the measure of how the running time of an algorithm increases with input
size n.
Factors affecting Time Complexity (2 Marks):
1. Input Size (n)
2. Number of Operations
Time complexity is commonly expressed using Big-O notation such as O(1), O(n), O(n²).

5)what are the keywords in python. define and list any 4

Definition:
Keywords in Python are reserved words that have special meaning and cannot be used as
variable names, function names, or identifiers.
Any 4 Python Keywords:
1. if – used for conditional statements
2. for – used for looping
3. while – used for looping
4. def – used to define a function
6)list out the rules for naming a variable in python
Rules for Naming a Variable
1. A variable name must start with a letter (a–z, A–Z) or underscore (_).
Example: name, _total
2. It cannot start with a number.
3. It can contain letters, numbers, and underscores only
4. Keywords cannot be used as variable names.
5. Variable names are case-sensitive.
7)what you mean by value and operand
Value:
A value is the data or information used in a program.
Example:
x = 20
Here, 20 is a value.
Operand:
An operand is the value or variable on which an operator acts.
Example:
10 + 5
Here, 10 and 5 are operands, and + is the operator.

8)explain about compilation error and runtime error


1. CompilationError(SyntaxError):
A compilation error occurs when the Python code violates syntax rules and cannot be
executed.
Example:
if x > 10
print(x)
(Missing: → Syntax Error)
[Link]:
A runtime error occurs while the program is running due to invalid operations.
Example:
print (10 / 0)
(ZeroDivisionError occurs during execution)

9)Give hints on tuple assignment


Tuple assignment is a way of assigning multiple values to multiple variables in a single
statement using a tuple.
Multiple variables are assigned at the same time.
a, b = 10, 20
Here, a = 10 and b = 20.

10)define the hierarchy of operators. Give example


Definition:
The hierarchy of operators (operator precedence) refers to the order in which operators are
evaluated in an expression.
Order (High to Low):
1. () – Parentheses
2. ** – Exponentiation
3. *, /, //, % – Multiplication, Division
4. +, - – Addition, Subtraction
Example:
result = 2 + 3 * 4
print(result)
Output: 14

11)list the steps involved in the problem-solving process

1)Problem Definition
2)Algorithm Design
3)Flowchart (Optional)
4)Coding
5)Testing & Debugging

12)explain the steps involved in converting temperature from farenheit to Celsius


Read the temperature in Fahrenheit (F).
Apply the formula:
C=(F−32)×59C = (F - 32) \times \frac{5}{9}C=(F−32)×95
Calculate the value of Celsius (C).
Display the result.
Example in Python:
F = 98
C = (F - 32) * 5/9
print(C)

13) list merits and demerits of a flowchart

Merits:
1. Easy to understand and visualize the program logic.
2. Helps in detecting errors before coding.
Demerits:
1. Difficult to modify once drawn.
2. Becomes complex and confusing for large programs.

14) explain the difference between an algorithm and pseudocode.

Algorithm Pseudocode
An algorithm is a step-by-step Pseudocode is a structured way of writing the
procedure to solve a problem. algorithm using programming-like statements.
It is written in simple English It uses keywords and indentation similar to
language. programming languages.
Example: Add two numbers step by Example: READ A, B → SUM = A + B → PRINT
step. SUM

15)explain the difference between high level and low-level languages

High-Level Language Low-Level Language


Easy to read, write and understand. Difficult to read and understand.
Uses English-like statements. Uses machine code or assembly instructions.
Portable (runs on different systems). Machine dependent.
Example: Python, Java Example: Assembly Language, Machine Language
16)explain the diff

Interactive Mode Script Mode


Commands are executed line by line The entire program is written and then executed
immediately. at once.
Used for quick testing and simple
Used for writing and running full programs.
calculations.
Code must be saved as a .py file before
No need to save the code.
execution.

17)list the advantages of python programming

1)Easy to Learn and Use


2)Platform Independent
3)Large Standard Library
4)Supports Multiple Programming Paradigms

18) list the types of errors in python


Syntax Errors – error in Python grammar rules.
Example: Missing colon: in an if statement.
Runtime Errors – Occur during program execution.
Example: Division by zero (ZeroDivisionError).
Logical Errors – Program runs without error but gives incorrect output.

19) define operator precedence in python

Operator precedence in python determines the order in which operations are performed in an
expression.

Operations with higher precedence are executed first.

20)Define the term expression in python.


Definition:
An expression in Python is a combination of values, variables, and operators that produces a
result.
Example:
x=5+3
Here, 5 + 3 is an expression that evaluates to 8.

You might also like