SSC Resources · Ict
Lecture slides and notes for Python Problems from the Ict module in SSC Resources by Md Ahbab. 5 pages.

Python Problems Theory Questions (2 Marks Each) 1. Explain the differences among the break, continue, and pass statements in Python. 2. What is type casting in Python? 3. Differentiate between a for loop and a while loop in Python. 4. What is a nested loop in Python? 5. Describe how conditional statements work in Python. Coding Problems (5 Marks Each) 1. Even or Odd Checker 2. Number Sequence with Skip (using continue) 3. Sum of Numbers from 1 to n 4. Factorial Calculator (using while loop) 5. Password Verification with Attempts 6. Multiplication Table 7. Star Pattern (Right-Angled Triangle) 8. Number Pyramid Pattern 9. Inverted Number Triangle Pattern 10. Prime Number Generator up to n 11. Reverse Digits of an Integer 12. Find the First Number Divisible by 7 and 5 13. Menu-Driven Calculator 14. Fibonacci Series Generator 15. Palindrome Number Checker 16. Leap Year Checker 17. Armstrong Number Checker 18. Sum of Digits 19. Reverse a String 20. Perfect Number Checker
Solutions Theory Questions (2 Marks Each) 1. break, continue, pass o break: Exits the loop entirely. o continue: Skips the current iteration and continues with the next. o pass: Does nothing; it's a placeholder. 2. Type Casting Converting one data type to another, like int("5") to convert a string to an integer. 3. for vs while loop o for: Used when you know how many times to loop. o while: Used when the loop continues based on a condition. 4. Nested Loop A loop inside another loop. Useful for patterns or matrix operations. 5. Conditional Statements Use if, elif, and else to run different code blocks based on conditions. Coding Problems (5 Marks Each) 1. Even or Odd Checker num = int(input("Enter a number: ")) if num % 2 == 0: print("Even number") else: print("Odd number") 2. Number Sequence with Skip (using continue) for i in range(1, 11): if i == 5: continue # Skip printing 5 print(i) 3. Sum of Numbers from 1 to n n = int(input("Enter a number: ")) total = 0 for i in range(1, n+1): total += i print("Sum:", total) 4. Factorial Calculator (using while loop) n = int(input("Enter a number: ")) factorial = 1 i = 1 while i <= n: factorial *= i
i += 1 print("Factorial:", factorial) 5. Password Verification with Attempts correct_password = "hello123" attempts = 3 while attempts > 0: entered = input("Enter password: ") if entered == correct_password: print("Access granted!") break else: print("Wrong password.") attempts -= 1 if attempts == 0: print("Access denied.") 6. Multiplication Table num = int(input("Enter a number: ")) for i in range(1, 11): print(f"{num} x {i} = {num*i}") 7. Star Pattern (Right-Angled Triangle) rows = int(input("Enter number of rows: ")) for i in range(1, rows+1): print("*" * i) 8. Number Pyramid Pattern rows = int(input("Enter rows: ")) for i in range(1, rows+1): for j in range(1, i+1): print(j, end=" ") print() 9. Inverted Number Triangle Pattern rows = int(input("Enter rows: ")) for i in range(rows, 0, -1): for j in range(1, i+1): print(j, end=" ") print() 10. Prime Number Generator up to n n = int(input("Generate primes up to: ")) for num in range(2, n+1): is_prime = True for i in range(2, int(num**0.5)+1): if num % i == 0: is_prime = False break if is_prime: print(num) 11. Reverse Digits of an Integer num = int(input("Enter a number: ")) rev = 0 while num > 0: digit = num % 10