0% found this document useful (0 votes)
47 views15 pages

Questions On Every Topic

The document outlines various programming tasks and their specifications, including checking number properties, handling lists, tuples, sets, dictionaries, and error handling. Each task includes input formats, output formats, constraints, and test cases for validation. The tasks cover fundamental programming concepts suitable for beginners.

Uploaded by

sattysr3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views15 pages

Questions On Every Topic

The document outlines various programming tasks and their specifications, including checking number properties, handling lists, tuples, sets, dictionaries, and error handling. Each task includes input formats, output formats, constraints, and test cases for validation. The tasks cover fundamental programming concepts suitable for beginners.

Uploaded by

sattysr3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Check if a number is positive, negative, or zero


 Input Format: A single integer n
 Output Format: "Positive", "Negative", or "Zero"
 Constraints: -1000 <= n <= 1000
 Test Cases:
o Input: 5 → Output: Positive
o Input: 0 → Output: Zero
o Input: -3 → Output: Negative

2. Check if a number is even or odd


 Input Format: A single integer n
 Output Format: "Even" or "Odd"
 Constraints: -1000 <= n <= 1000
 Test Cases:
o Input: 6 → Output: Even
o Input: 7 → Output: Odd
o Input: 0 → Output: Even
3. Check if a person is eligible to vote
 Input Format: A single integer age
 Output Format: "Eligible" or "Not Eligible"
 Constraints: 0 <= age <= 120
 Test Cases:
o Input: 20 → Output: Eligible
o Input: 17 → Output: Not Eligible
o Input: 18 → Output: Eligible

4. Find the greatest of two numbers


 Input Format: Two space-separated integers a and b
 Output Format: The greater number (or either if equal)
 Constraints: -1000 <= a, b <= 1000
 Test Cases:
o Input: 5 3 → Output: 5
o Input: 2 8 → Output: 8
o Input: 7 7 → Output: 7
5. Check if a year is a leap year
 Input Format: A single integer year
 Output Format: "Leap Year" or "Not a Leap Year"
 Constraints: 1000 <= year <= 3000
 Test Cases:
o Input: 2020 → Output: Leap Year
o Input: 1900 → Output: Not a Leap Year
o Input: 2000 → Output: Leap Year

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

2. Find the largest number in a list


 Input Format: A list of integers separated by space
 Output Format: The maximum value
 Test Cases:
o Input: 1 99 3 4 → Output: 99
o Input: -10 -3 -50 → Output: -3
o Input: 5 → Output: 5

3. Count the number of even numbers in a list


 Input Format: A list of integers
 Output Format: Count of even numbers
 Test Cases:
o Input: 1 2 3 4 5 6 → Output: 3
o Input: 7 9 11 → Output: 0
o Input: 0 2 4 6 → Output: 4

4. Print the list in reverse order


 Input Format: A list of integers
 Output Format: Reversed list, space-separated
 Test Cases:
o Input: 1 2 3 → Output: 3 2 1
o Input: 10 20 → Output: 20 10
o Input: 5 → Output: 5

5. Remove duplicates from a list


 Input Format: A list of integers
 Output Format: Unique elements in the order they
appeared
 Test Cases:
o Input: 1 2 2 3 4 4 → Output: 1 2 3 4
o Input: 5 5 5 5 → Output: 5
o Input: 1 2 3 → Output: 1 2 3

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

2. Check if an element exists in a tuple


 Input Format: A tuple and an integer to search
 Output Format: "Found" or "Not Found"
 Test Cases:
o Input: (1, 2, 3) → Output: Found
o Input: (4, 5, 6) → Output: Not Found
o Input: (10,) → Output: Found

3. Find the length of a tuple


 Input Format: A tuple
 Output Format: Length of the tuple
 Test Cases:
o Input: (1, 2, 3) → Output: 3
o Input: (10, 20) → Output: 2
o Input: (5,) → Output: 1

4. Count occurrences of an element in a tuple


 Input Format: A tuple and an element to count
 Output Format: Count of occurrences
 Test Cases:
o Input: (1, 2, 2, 3) → Output: 2
o Input: (4, 4, 4, 4) → Output: 4
o Input: (5, 6, 7) → Output: 0

5. Convert a list to a tuple


 Input Format: A list of integers
 Output Format: A tuple of integers
 Test Cases:
o Input: 1 2 3 → Output: (1, 2, 3)
o Input: 10 20 → Output: (10, 20)
o Input: 5 → Output: (5,)

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

2. Find the union of two sets


 Input:
123
345
 Output: 1 2 3 4 5
 More cases:
o Input: 1 1 1 2 2 → Output: 1 2
o Input: 10 20 30 40 → Output: 10 20 30 40

3. Find the intersection of two sets


 Input:
123
234
 Output: 2 3
 More cases:
o Input: 5 6
7 8 → Output: (empty)
o Input: 10 20
10 30 Output: 10
4. Check if one set is a subset of another
 Input:
12
123
 Output: Yes
 More cases:
o Input: 4 5\n1 2 3 → Output: No
o Input: 10\n10 20 → Output: Yes
5. Add an element to a set
 Input:
123
4
 Output: 1 2 3 4
 More cases:
o Input: 5 6\n5 → Output: 5 6
o Input: 7 8\n9 → Output: 7 8 9

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}

2. Find value by key in a dictionary


 Input:
a1b2
b
 Output: 2
 More cases:
o Input: x 10 y 20\nz → Output: Key not found
o Input: k 5\nk → Output: 5

3. Count frequency of words


 Input: apple banana apple
 Output:
apple: 2
banana: 1
 More cases:
o Input: cat cat dog → Output: cat: 2\ndog: 1
o Input: one → Output: one: 1

4. Update a value in a dictionary


 Input:
a1b2
a 10
 Output: {'a': 10, 'b': 2}
 More cases:
o Input: x 5\nx 15 → Output: {'x': 15}
o Input: k 0 l 1\nl 9 → Output: {'k': 0, 'l': 9}

5. Delete a key from dictionary


 Input:
a1b2
a
 Output: {'b': 2}
 More cases:
o Input: x 5 y 6\nz → Output: Key not found
o Input: k 0\nk → Output: {}

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

You might also like