Python NCERT Logical Questions
Python NCERT Logical Questions
Strings
1. Count the number of vowels in a string. Example: Input: 'hello world' -> Output: 3
2. Check whether a given string is a palindrome. Example: Input: 'madam' -> Output: True
3. Replace all occurrences of 'a' with '@'. Example: Input: 'apple' -> Output: '@pple'
4. Convert the first letter of each word to uppercase. Input: 'hello world' -> Output: 'Hello World'
5. Find the frequency of each character. Input: 'banana' -> Output: {'b':1,'a':3,'n':2}
7. Find the longest word in a string. Input: 'I love programming' -> Output: 'programming'
8. Count the number of words. Input: 'Hello from the other side' -> Output: 5
9. Check if two strings are anagrams. Input: 'listen', 'silent' -> Output: True
10. Remove all punctuation. Input: 'Hello, world!' -> Output: 'Hello world'
11. Count occurrences of a specific word. Input: 'hello world hello' -> Output for 'hello': 2
12. Replace spaces with hyphens. Input: 'hello world' -> Output: 'hello-world'
13. Check whether the string starts with a vowel. Input: 'apple' -> Output: True
14. Swap the case of each letter. Input: 'HeLLo' -> Output: 'hEllO'
16. Check if string contains only digits. Input: '12345' -> Output: True
17. Count uppercase and lowercase letters. Input: 'Hello' -> Output: upper:1, lower:4
19. Find index of first occurrence of substring. Input: 'hello', 'l' -> Output: 2
20. Remove all spaces. Input: 'a b c' -> Output: 'abc'
Lists
1. Find max and min in a list. Input: [3,1,4] -> Output: max=4, min=1
6. Find sum and average. Input: [2,4,6] -> Output: sum=12, avg=4
10. Separate even and odd. Input: [1,2,3,4] -> Output: even=[2,4], odd=[1,3]
16. Find common elements. Input: [1,2], [2,3] -> Output: [2]
17. Check if lists are identical. Input: [1,2], [1,2] -> Output: True
18. Find difference between max and min. Input: [3,7] -> Output: 4
Dictionaries
1. Create dictionary of student marks. Input: names=['A','B'], marks=[90,80] -> Output: {'A':90,'B':80}
15. Swap keys and values. Input: {'a':1,'b':2} -> Output: {1:'a',2:'b'}
18. Add new key. Input: {'a':1}, add 'b':2 -> Output: {'a':1,'b':2}
Tuples