10 Intermediate Python Questions

Answer attached. Never see them until you tired for an hour

 

1. Remove Duplicates From a List (Without Using set)

Input: [1, 2, 2, 3, 4, 4, 5]
Output: [1, 2, 3, 4, 5]

2. Count Word Frequency in a Sentence

Input: "python is fun and python is powerful"
Output:

3. Check if a String Is a Palindrome (Ignore Case & Spaces)

Examples:

  • "Race car" → True
  • "Python" → False

 

4. Find All Prime Numbers Between 1 and N

Input: N = 50
Output: list of primes up to 50.

5. Create a Function That Returns the Fibonacci Sequence Up to N Terms

Input: n = 10
Output: first 10 Fibonacci numbers.

 

6. Find the Second Largest Number in a List

Input: [10, 20, 4, 45, 99]
Output: 45

 

7. Merge Two Dictionaries

Input:

a = {“x”: 1, “y”: 2} b = {“y”: 3, “z”: 4}

Output:
{"x": 1, "y": 3, "z": 4}
(Values from second dict override first)

 

8. Read a File and Count How Many Lines It Has

(Assume the file exists)

 

9. Create a Class BankAccount With:

  • deposit(amount)
  • withdraw(amount)
  • check_balance()

Test it with some transactions.

 

10. Given a List of Dictionaries, Sort by a Key

Input:

students = [ {“name”: “A”, “score”: 85}, {“name”: “B”, “score”: 92}, {“name”: “C”, “score”: 78} ]

Sort by score (descending).

Exercise Files
Quis1.png
Size: 63.01 KB
Quis2.png
Size: 61.26 KB
Quis3.png
Size: 32.75 KB
Quis4.png
Size: 65.55 KB
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare