model_questions_py.md (11484B)
1 --- 2 source: 'docs/semester_2/model_questions_py.md' 3 title: '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline; margin-bottom:-2px; margin-right:6px;"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 8h8"/><path d="M7 12h10"/><path d="M7 16h6"/></svg> Model Questions: Programming for Problem Solving using Python' 4 --- 5 6 # Model Questions: Programming for Problem Solving using Python 7 ### Paper Code: SEC (NEP, WBSU — Sem 2) 8 9 --- 10 11 ::: info How to use this file 12 This is a **sure-shot / high-priority** list built directly on the SEC Python study material 13 (Modules 1–6). All 8 practical programs from the syllabus are included **in full** below — 14 memorise and be able to reproduce each one, since the practical exam draws directly from this set. 15 ::: 16 17 ## Unit 1 — Program Planning & Problem Solving Techniques (Module 1 & 2) 18 19 **Q1.** What is meant by **Program Design**? Differentiate between **Top-down** and **Bottom-up** programming approaches with examples. 20 21 **Q2.** What is **Structured Programming**? Explain the three structured control flows (sequence, selection, repetition) it relies on, and why it avoids unstructured jumps like `goto`. 22 23 **Q3.** What is an **algorithm**? How does it differ from a **flowchart**? List the standard flowchart symbols (oval, rectangle, diamond, parallelogram) and what each represents. 24 25 **Q4.** What is a **decision table**? When is it preferred over a flowchart for representing logic? 26 27 **Q5.** What is **debugging**? Explain the three categories of programming errors — **Syntax Errors**, **Runtime Errors (Exceptions)**, and **Logical Errors** — with one example of each. 28 29 30 ## Unit 2 — Overview & Introduction to Python (Module 3 & 4) 31 32 **Q6.** Explain the structure of a Python program. How does Python use **indentation** instead of curly braces `{}` to define code blocks? What is the standard indentation convention? 33 34 **Q7.** What are **tokens** in Python? Explain the three types: **Keywords**, **Identifiers**, and **Literals**, with rules for naming identifiers and two examples of each. 35 36 **Q8.** List and explain all categories of operators in Python: **Arithmetic**, **Relational**, **Logical**, **Assignment**, and **Ternary (Conditional)**. Give one example expression for each. Why does Python not support `++` or `--`? 37 38 **Q9.** Differentiate between `/` (true division), `//` (floor division), and `%` (modulus) in Python with example outputs for `17 / 5`, `17 // 5`, and `17 % 5`. 39 40 41 ## Unit 3 — Creating Python Programs: Input, Conditions & Loops (Module 5) 42 43 **Q10.** Explain the `input()` function in Python. How is it different from `input("prompt")`? Why does `input()` always return a **string**, and how do you convert it to a number? 44 45 **Q11.** Write a short program that takes multiple user inputs (e.g., name, favourite animal, colour, number) and prints them in a formatted sentence using an f-string. 46 47 **Q12.** Explain the Python **if statement** with syntax and an example. What is the role of **indentation** in an if-block? What error occurs if the block under `if` is not indented? 48 49 **Q13.** Can multiple statements be written inside a single `if` block? What rule must be followed for them? Give an example (e.g., checking voting eligibility). 50 51 **Q14.** Explain how a **boolean variable** can be used directly in an `if` condition without a comparison operator, with an example (e.g., `logged_in = True`). 52 53 **Q15.** Explain the **for loop** in Python with the `range()` function. Write a program to print numbers from 1 to 8 using a `for` loop, and another to iterate over a list of fruits. 54 55 **Q16.** Explain the jump statements **`break`**, **`continue`**, and **`pass`** in Python with one example each. What is the key difference between `break` and `continue`? 56 57 **Q17.** What is a **function** in Python? How is it defined using `def`? What are **default arguments** in a function — explain with an example. 58 59 60 ## Unit 4 — Practical Programs (Module 6) — Sure-Shot Practical Questions 61 62 ::: tip Practical Exam Note 63 These 8 programs are **directly from your syllabus's practical list**. Learn to write each one from memory and be ready to explain the logic line-by-line — this is the most likely source of your practical exam question. 64 ::: 65 66 ### Q18. Temperature Conversion (Menu-Driven) 67 68 Write a **menu-driven** Python program to convert Fahrenheit to Celsius and Celsius to Fahrenheit based on user choice. 69 70 ```python 71 def temp_conversion(): 72 print("--- Temperature Converter ---") 73 print("1. Fahrenheit to Celsius") 74 print("2. Celsius to Fahrenheit") 75 choice = input("Enter choice (1 or 2): ") 76 if choice == '1': 77 f = float(input("Enter temperature in Fahrenheit: ")) 78 c = (f - 32) * 5 / 9 79 print(f"{f}°F is equal to {c:.2f}°C") 80 elif choice == '2': 81 c = float(input("Enter temperature in Celsius: ")) 82 f = (c * 9 / 5) + 32 83 print(f"{c}°C is equal to {f:.2f}°F") 84 else: 85 print("Invalid choice!") 86 87 # Call the function 88 temp_conversion() 89 ``` 90 91 ### Q19. Student Grade Calculator 92 93 Write a Python program that takes marks for 5 subjects, computes the total and percentage, and assigns a grade (`A+` to `F`) using `if-elif-else`. 94 95 ```python 96 # Student Grade Calculator 97 name = input("Enter student's name: ") 98 print("Enter marks for 5 subjects (out of 100):") 99 sub1 = float(input("Subject 1: ")) 100 sub2 = float(input("Subject 2: ")) 101 sub3 = float(input("Subject 3: ")) 102 sub4 = float(input("Subject 4: ")) 103 sub5 = float(input("Subject 5: ")) 104 105 # Calculate total and percentage 106 total = sub1 + sub2 + sub3 + sub4 + sub5 107 percentage = total / 5 108 109 # Determine grade 110 if percentage >= 90: 111 grade = 'A+' 112 elif percentage >= 80: 113 grade = 'A' 114 elif percentage >= 70: 115 grade = 'B' 116 elif percentage >= 60: 117 grade = 'C' 118 elif percentage >= 50: 119 grade = 'D' 120 else: 121 grade = 'F' 122 123 # Display results 124 print("\n--- Student Report ---") 125 print("Student Name:", name) 126 print("Total Marks:", total, "/ 500") 127 print("Percentage:", round(percentage, 2), "%") 128 print("Grade:", grade) 129 ``` 130 131 ### Q20. Area Calculator Using Functions (Menu-Driven) 132 133 Write a **menu-driven** Python program using **separate functions** to compute the area of a circle, rectangle, and triangle. 134 135 ```python 136 # Function to calculate area of a circle 137 def area_circle(): 138 radius = float(input("Enter the radius of the circle: ")) 139 area = 3.14 * radius * radius 140 print(f"Area of the Circle = {area:.2f}") 141 142 # Function to calculate area of a rectangle 143 def area_rectangle(): 144 length = float(input("Enter the length of the rectangle: ")) 145 breadth = float(input("Enter the breadth of the rectangle: ")) 146 area = length * breadth 147 print(f"Area of the Rectangle = {area:.2f}") 148 149 # Function to calculate area of a triangle 150 def area_triangle(): 151 base = float(input("Enter the base of the triangle: ")) 152 height = float(input("Enter the height of the triangle: ")) 153 area = 0.5 * base * height 154 print(f"Area of the Triangle = {area:.2f}") 155 156 # Main menu function 157 def menu(): 158 while True: 159 print("\n--- Area Calculator ---") 160 print("1. Area of Circle") 161 print("2. Area of Rectangle") 162 print("3. Area of Triangle") 163 print("4. Exit") 164 choice = input("Enter your choice (1-4): ") 165 if choice == '1': 166 area_circle() 167 elif choice == '2': 168 area_rectangle() 169 elif choice == '3': 170 area_triangle() 171 elif choice == '4': 172 print("Exiting the program...") 173 break 174 else: 175 print("Invalid choice! Please try again.") 176 177 # Call the menu function 178 menu() 179 ``` 180 181 ### Q21. Fibonacci Series up to N Terms 182 183 Write a Python program to print the Fibonacci series up to `N` terms entered by the user. 184 185 ```python 186 # Fibonacci Series up to N Terms 187 n = int(input("Enter the number of terms: ")) 188 a = 0 189 b = 1 190 print("Fibonacci Series:") 191 for i in range(n): 192 print(a, end=" ") 193 c = a + b 194 a = b 195 b = c 196 ``` 197 198 ### Q22. Factorial of a Number 199 200 Write a Python program using a **function** to compute the factorial of a number. Handle the case of a negative input. 201 202 ```python 203 # Function to calculate factorial 204 def factorial(n): 205 fact = 1 206 for i in range(1, n + 1): 207 fact = fact * i 208 return fact 209 210 # Main program 211 num = int(input("Enter a number: ")) 212 if num < 0: 213 print("Factorial is not defined for negative numbers.") 214 else: 215 result = factorial(num) 216 print(f"Factorial of {num} is {result}") 217 ``` 218 219 ### Q23. Prime Number Checker 220 221 Write a Python program to check whether a given number is prime. 222 223 ```python 224 # Prime Number Checker 225 num = int(input("Enter a number: ")) 226 if num <= 1: 227 print(num, "is not a Prime Number") 228 else: 229 is_prime = True 230 for i in range(2, num): 231 if num % i == 0: 232 is_prime = False 233 break 234 if is_prime: 235 print(num, "is a Prime Number") 236 else: 237 print(num, "is not a Prime Number") 238 ``` 239 240 ### Q24. String Palindrome Checker 241 242 Write a Python program using a **function** to check whether a given string is a palindrome (case-insensitive). 243 244 ```python 245 # Function to check palindrome 246 def is_palindrome(text): 247 # Convert to lowercase for case-insensitive comparison 248 text = text.lower() 249 # Reverse the string and compare 250 if text == text[::-1]: 251 return True 252 else: 253 return False 254 255 # Main program 256 string = input("Enter a string: ") 257 if is_palindrome(string): 258 print(f'"{string}" is a Palindrome') 259 else: 260 print(f'"{string}" is not a Palindrome') 261 ``` 262 263 ### Q25. Sum of Mathematical Series: 1 + 1/2 + 1/3 + … + 1/n 264 265 Write a Python program to compute the sum of the series `1 + 1/2 + 1/3 + ... + 1/n` for a user-given `n`. 266 267 ```python 268 # Sum of the series: 1 + 1/2 + 1/3 + ... + 1/n 269 n = int(input("Enter the value of n: ")) 270 sum_series = 0 271 for i in range(1, n + 1): 272 sum_series += 1 / i 273 print(f"Sum of the series up to {n} terms = {sum_series:.4f}") 274 ``` 275 276 277 ## Quick Reference: Syllabus Unit Map 278 279 | Unit | Topics | Questions | 280 |------|--------|-----------| 281 | 1 | Program Design, Structured Programming, Algorithms, Flowcharts, Debugging | Q1–Q5 | 282 | 2 | Python Structure, Indentation, Tokens, Operators | Q6–Q9 | 283 | 3 | Input, If Statements, Loops, Jump Statements, Functions | Q10–Q17 | 284 | 4 | Practical Programs (all 8 syllabus programs) | Q18–Q25 | 285 286 --- 287 288 ::: tip Exam Strategy 289 - **Theory (5-mark) sure-shots**: Top-down vs bottom-up, types of errors (syntax/runtime/logical), tokens (keywords/identifiers/literals), operator categories, `break` vs `continue` vs `pass`. 290 - **Practical (10–15 mark) sure-shots**: All 8 programs above are the entire practical syllabus — expect the exam to pick directly from this list. Practice writing each **without** looking, including proper indentation and f-string formatting. 291 - Common trap: remember `input()` always returns a **string** — always cast with `int()` or `float()` before doing arithmetic. 292 - Practice explaining the **logic** of each program in plain words (viva-style), not just typing the code. 293 ::: 294 ::: info Key Programs to Memorise 295 Menu-driven Temperature Converter · Student Grade Calculator (if-elif ladder) · Menu-driven Area Calculator (functions) · Fibonacci Series (loop) · Factorial (function) · Prime Checker · Palindrome Checker (string slicing `[::-1]`) · Series Sum (1 + 1/2 + … + 1/n) 296 :::