0% found this document useful (0 votes)
2 views11 pages

Model Question Paper 3 Answers Python

Uploaded by

appkumar5457
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)
2 views11 pages

Model Question Paper 3 Answers Python

Uploaded by

appkumar5457
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

MODEL QUESTION PAPER -- 03

PART - A

1. C) To plan a solution using simple, readable steps

2. C) Sorting problem

3. B) Designing a sequence of steps to solve a problem

4. D) Making random guesses

5. B) Pattern Recognition

6. B) Algorithm

7. B) Exponent (**)

8. B) Violation of language rules (e.g., missing colon or parentheses)

9. D) #

10. C) real

11. C) input()

12. D) All of the above

13. B) while True: with no break

14. B) 3

15. B) Exits the loop immediately


16. Algorithm
17. Programming
18. NO
19. True
20. Import

PART – B

1. Algorithmic thinking is the process of solving a problem by creating a clear step-by-


step procedure or set of instructions.

2. Two types of problems where algorithmic solutions are commonly used are:

• Sorting problems

• Searching problems
3. A variable in programming is a named storage location used to store data that can
change during program execution.

4. loop in programming is a control structure that repeats a block of code multiple


times until a condition becomes false.

5. Two tools or techniques used for debugging in Python are:

• print() statements

• Python debugger (pdb)

6. Compile-time errors occur before the program runs due to syntax mistakes, while
run-time errors occur during program execution due to invalid operations or
unexpected conditions.

7. A function in Python is a reusable block of code designed to perform a specific task.

8. Modular programming is a programming approach where a large program is divided


into smaller, independent modules or functions for easier development, testing, and
maintenance.

PART -- C

1) Algorithmic thinking:
Algorithmic thinking means solving a problem step by step.

Tea making example:


Boil water → Add tea powder → Add milk and sugar → Boil → Filter → Serve.

2) Significance of data types in Python:


Data types define the kind of data stored in a variable. They help Python perform correct
operations.

Example:

age = 18 # int

name = "Ram" # str

3)Syntax vs Semantic errors:

Syntax Error Semantic Error

Breaks Python rules Wrong logic

Program won’t run Program runs but gives wrong output

Example of syntax error:

if x > 5
print(x)

Example of semantic error:

avg = a + b / 2

4)Constants vs Variables:

Variable Constant

Value can change Value remains fixed

Example:

marks = 90

PI = 3.14

5)for loop vs while loop:

for loop while loop

Used for fixed repetitions Used until condition becomes false

for loop example:

for i in range(3):

print(i)

while loop example:

x=1

while x <= 3:

print(x)

x += 1

6)Importance of testing after fixing errors:


Testing checks whether the error is fixed correctly and ensures no new errors are
created.

7)Functions vs Packages:

Functions Packages

Reusable block of code Collection of modules

Example:

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

import math

8)Advantages of built-in modules:

• Save time

• Provide ready-made functions

• Make coding easier

Examples: math, random, datetime.

PART – D (SECTION – 1)

1)Four Pillars of Computational Thinking:

Pillar Meaning Example

Breaking a problem into Making a website by dividing into login,


Decomposition
smaller parts homepage, payment

Pattern Recognizing same steps in solving math


Finding similarities
Recognition problems

Focusing only on
Abstraction Using a map instead of real city details
important details

Algorithmic Creating step-by-step


Tea making steps
Thinking solution

2)Tokens in Python:
Tokens are the smallest units in a Python program.

Types of tokens:

Type Example

Keywords if, while

Identifiers name, total

Literals 10, "Hello"

Operators +, -, *

Separators (), :
Example:

x = 10 + 5

3)Rules for valid variable names in Python:

• Must start with letter or _

• Cannot start with number

• No spaces allowed

• Cannot use keywords

Valid examples:

name = "Ram"

_age = 20

Invalid examples:

2name = "Ram"

my name = "Ram"

4)String formatting methods:

Using % formatting:

name = "Mark"

subject = "Thinking Programming"

marks = 95

-print("Student %s has scored %d marks in %s." % (name, marks, subject))

Using format() :

print("Student {} has scored {} marks in {}.".format(name, marks, subject))

Using f-string:

print(f"Student {name} has scored {marks} marks in {subject}.")

5)Flow control statements in Python:

Type Purpose Example

Conditional Statements Decision making if, else

Looping Statements Repeating code for, while


Type Purpose Example

Jump Statements Change loop flow break, continue

Example:

if x > 0:

print("Positive")

6)Corrected Program:

for i in range(1, 21):

if i == 4 or i == 14:

continue

print(i)

7)Need for functions in Python:


Functions reduce repetition and make programs easier to manage.

Function without arguments:

def greet():

print("Hello")

greet()

Function with arguments:

def add(a, b):

print(a + b)

add(2, 3)

8)Significance of modules and packages:


Moule:

• Organize the code into logical parts


• Reuse the code in multiple programs
• Avoid making conflicts
• Improve readability and maintainability\

Package:
• Organize the Large project
• Group related modules together
• Provides hierarchical structure
• Improve stability

Example:

import math

print([Link](25))

PART – D (Section – 2)

1. Tokens in the Python statement

Statement:

while count < 10:

result = result + value_1 - 3

Token Category Explanation

while Keyword Used for looping

count Identifier Variable name

< Operator Comparison operator

10 Literal Integer value

: Separator Starts loop block

result Identifier Variable name

= Operator Assignment operator

+ Operator Addition operator

value_1 Identifier Variable name

- Operator Subtraction operator

3 Literal Integer value

2) ATM Machine Program

pin = 1234

balance = 5000
entered_pin = int(input("Enter PIN: "))

if entered_pin == pin:

amount = int(input("Enter withdrawal amount: "))

if amount > balance:

print("Insufficient balance")

elif amount % 100 != 0:

print("Amount should be multiple of 100")

else:

balance -= amount

print("Withdrawal successful")

print("Remaining balance:", balance)

else:

print("Incorrect PIN")

3) Bookstore Discount Program

amount = float(input("Enter total purchase amount: "))

if amount >= 5000:

discount = 25

elif amount >= 3000:

discount = 15
elif amount >= 1000:

discount = 5

else:

discount = 0

discount_amount = amount * discount / 100

final_amount = amount - discount_amount

print("Discount:", discount, "%")

print("Final Amount:", final_amount)

4) Modular Program for Student Grade

def get_marks():

math = float(input("Enter Math marks: "))

science = float(input("Enter Science marks: "))

english = float(input("Enter English marks: "))

return math, science, english

def calculate_average(m, s, e):

return (m + s + e) / 3

def find_grade(avg):

if avg >= 90:

return "A"

elif avg >= 75:

return "B"

elif avg >= 50:


return "C"

else:

return "F"

def main():

m, s, e = get_marks()

avg = calculate_average(m, s, e)

grade = find_grade(avg)

print("Average:", avg)

print("Grade:", grade)

main()

5) Types of Function Arguments in Python

Type Example

Positional Arguments add(2,3)

Keyword Arguments add(a=2,b=3)

Default Arguments def greet(name="User")

Variable Length Arguments def total(*num)

Examples:

def add(a, b):

print(a + b)

add(2, 3)

def greet(name="User"):

print(name)

greet()

You might also like