Questions On Every Topic
Questions On Every Topic
Topic: List
1. Find the sum of all elements in a list
Input Format: A list of integers separated by space
Output Format: Sum of the elements
Constraints: 1 <= length <= 1000, -1000 <= element <=
1000
Test Cases:
o Input: 1 2 3 4 → Output: 10
o Input: -1 -2 5 → Output: 2
o Input: 0 0 0 → Output: 0
Topic: Tuple
1. Access the second element in a tuple
Input Format: A tuple of integers (min 2 elements)
Output Format: Second element
Test Cases:
o Input: (1, 2, 3) → Output: 2
o Input: (10, 20) → Output: 20
o Input: (5, 6, 7, 8) → Output: 6
Topic Set
1. Remove duplicates from a list using a set
Input: 1 2 2 3
Output: 1 2 3
Constraints: 1 <= length <= 1000
More cases:
o Input: 4 4 4 → Output: 4
o Input: 10 20 10 30 → Output: 10 20 30
Dictionary
1. Create a dictionary from keys and values
Input:
abc
123
Output: {'a': 1, 'b': 2, 'c': 3}
More cases:
o Input: x y\n10 20 → Output: {'x': 10, 'y': 20}
o Input: key\n5 → Output: {'key': 5}
For Loops
1. Print all numbers from 1 to N
o Input: 5
o Output: 1 2 3 4 5
o Constraints: 1 <= N <= 100
2. Print square of first N numbers
o Input: 3
o Output: 1 4 9
3. Sum all even numbers from 1 to N
o Input: 10
o Output: 30
4. Count vowels in a string
o Input: banana
o Output: 3
5. Reverse list elements
o Input: 1 2 3
o Output: 3 2 1
Functions
1. Square of a number
o Input: 5
o Output: 25
2. Check if a number is even or odd
o Input: 7
o Output: Odd
3. Factorial of a number
o Input: 5
o Output: 120
4. Find maximum of three numbers
o Input: 10 5 7
o Output: 10
5. Count words in a sentence
o Input: Python is fun
o Output: 3
Error Handling
1. Handle division by zero
o Input: 5 0
o Output: Cannot divide by zero
2. Handle invalid integer input
o Input: hello
o Output: Invalid input
3. Handle missing key in dictionary
o Input:
x 10
y
o Output: Key not found
4. Handle index error in a list
o Input:
10 20
5
o Output: Index out of range
5. Handle file not found
o Input: myfile.txt
o Output: File not found