Sure, here are 200 problem-solving examples using for loops in Python along with their expected answers:
-
Write a program to find the sum of all odd numbers from 1 to 100.
Expected Output: 2500
-
Write a program to check if a given string is a palindrome.
Example Input: "racecar"
Expected Output: Yes
-
Write a program to find the factorial of a given number, say 6.
Expected Output: 720
-
Write a program to print the multiplication table of a given number, say 7.
Expected Output:
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
...
7 x 10 = 70
-
Write a program to find the sum of all digits in a given number, say 12345.
Expected Output: 15
-
Write a program to find the length of a given string.
Example Input: "Python Programming"
Expected Output: 18
-
Write a program to find the reverse of a given list.
Example Input: [5, 3, 2, 9, 1]
Expected Output: [1, 9, 2, 3, 5]
-
Write a program to check if a given number is Armstrong or not.
Example Input: 153
Expected Output: Armstrong
-
Write a program to find the second largest element in a given list.
Example Input: [7, 9, 3, 5, 2]
Expected Output: 7
-
Write a program to find the sum of all prime numbers from 1 to 50.
Expected Output: 328
-
Write a program to check if a given number is a palindrome.
Example Input: 12321
Expected Output: Yes
-
Write a program to check if a given string is a palindrome ignoring spaces.
Example Input: "A man a plan a canal Panama"
Expected Output: Yes
-
Write a program to find the sum of all digits in a given number.
Example Input: 98765
Expected Output: 35
-
Write a program to count the number of occurrences of a given character in a given string.
Example Input: "Hello World", 'o'
Expected Output: 2
-
Write a program to calculate the factorial of a given number using recursion.
Expected Output: 120
-
Write a program to find the largest prime factor of a given number, say 20.
Expected Output: 5
-
Write a program to check if a given number is perfect or not.
Example Input: 28
Expected Output: Perfect
-
Write a program to find the sum of all digits in a given number using recursion.
Example Input: 4567
Expected Output: 22
-
Write a program to find the average of all elements in a given list using recursion.
Example Input: [2, 4, 6, 8, 10]
Expected Output: 6
-
Write a program to find the sum of all elements in a given matrix.
Example Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected Output: 45
-
Write a program to multiply two matrices.
Example Input: [[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]]
Expected Output: [[58, 64], [139, 154]]
-
Write a program to find the common elements in two given lists.
Example Input: [1, 3, 5, 7, 9], [2, 3, 4, 6, 8]
Expected Output: [3]
-
Write a program to find the sum of all elements in a given dictionary.
Example Input: {'a': 1, 'b': 2, 'c': 3}
Expected Output: 6
-
Write a program to print the elements of a given list in reverse order.
Example Input: [5, 4, 3, 2, 1]
Expected Output: 1 2 3 4 5
-
Write a program to find the median of a given list.
Example Input: [3, 1, 4, 2, 5]
Expected Output: 3
-
Write a program to find the sum of all odd digits in a given number.
Example Input: 98765
Expected Output: 25
-
Write a program to find the common elements in multiple lists.
Example Input: [1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]
Expected Output: [4]
-
Write a program to find the length of the longest word in a given sentence.
Example Input: "Python is a powerful language"
Expected Output: 9
-
Write a program to find the sum of all elements in a given set.
Example Input: {1, 3, 5, 7, 9}
Expected Output: 25
-
Write a program to find the sum of all positive numbers in a given list.
Example Input: [-1, 2, -3, 4, -5]
Expected Output: 6
-
Write a program to find the minimum element in each row of a given matrix.
Example Input: [[10, 5, 8], [4, 7, 2], [9, 3, 6]]
Expected Output: [5, 2, 3]
-
Write a program to find the number of uppercase letters in a given string.
Example Input: "Hello World"
Expected Output: 2
-
Write a program to find the common keys in two given dictionaries.
Example Input: {'a': 1, 'b': 2, 'c': 3}, {'c': 4, 'd': 5, 'e': 6}
Expected Output: ['c']
-
Write a program to find the sum of all negative numbers in a given list.
Example Input: [-1, 2, -3, 4, -5]
Expected Output: -9
-
Write a program to find the maximum difference between two consecutive elements in a given list.
Example Input: [2, 5, 7, 4, 9]
Expected Output: 5
-
Write a program to find the number of lowercase letters in a given string.
Example Input: "Hello World"
Expected Output: 8
-
Write a program to find the number of elements in a given multidimensional list.
Example Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected Output: 9
-
Write a program to find the sum of all elements in a given tuple.
Example Input: (1, 2, 3, 4, 5)
Expected Output: 15
-
Write a program to swap the first and last elements in a given list.
Example Input: [5, 2, 8, 4]
Expected Output: [4, 2, 8, 5]
-
Write a program to find the number of characters that appears more than once in a given string.
Example Input: "Python Programming"
Expected Output: 2
-
Write a program to convert a given list of strings to uppercase.
Example Input: ['apple', 'banana', 'cherry']
Expected Output: ['APPLE', 'BANANA', 'CHERRY']
-
Write a program to remove all duplicate elements from a given list.
Example Input: [1, 2, 3, 2, 4, 1]
Expected Output: [1, 2, 3, 4]
-
Write a program to find the number of elements that appear more than once in a given list.
Example Input: [1, 2, 3, 2, 4, 1]
Expected Output: 2
-
Write a program to find the number of words in a given sentence.
Example Input: "Python is a powerful language"
Expected Output: 5
-
Write a program to find the longest word in a given sentence.
Example Input: "Python is a powerful language"
Expected Output: powerful
-
Write a program to find the sum of all elements in a given list excluding the first and last elements.
Example Input: [5, 2, 8, 4, 6]
Expected Output: 14
-
Write a program to concatenate all strings in a given list.
Example Input: ["Hello", "World", "!"]
Expected Output: HelloWorld!
-
Write a program to find the smallest missing positive number in a given list.
Example Input: [1, 2, 0, -1, 3, 4]
Expected Output: 5
-
Write a program to find the intersection of two given lists.
Example Input: [1, 2, 3, 4], [3, 4, 5, 6]
Expected Output: [3, 4]
-
Write a program to find the common elements in multiple sets.
Example Input: {1, 2, 3}, {2, 3, 4}, {3, 4, 5}
Expected Output: {3}
-
Write a program to remove all whitespace characters from a given string.
Example Input: "Hello World"
Expected Output: HelloWorld
-
Write a program to count the number of elements that are divisible by a given number in a given list.
Example Input: [1, 2, 3, 4, 5], 2
Expected Output: 2
-
Write a program to find the square of each element in a given list.
Example Input: [1, 2, 3, 4, 5]
Expected Output: [1, 4, 9, 16, 25]
-
Write a program to remove all punctuation characters from a given string.
Example Input: "Hello, World!"
Expected Output: HelloWorld
-
Write a program to check if a given list is sorted in non-decreasing order.
Example Input: [1, 2, 3, 5, 4]
Expected Output: No
-
Write a program to merge two sorted lists into a single sorted list.
Example Input: [1, 3, 5], [2, 4, 6]
Expected Output: [1, 2, 3, 4, 5, 6]
-
Write a program to extract all numbers from a given string.
Example Input: "Hello 123 World 456!"
Expected Output: [123, 456]
-
Write a program to find the sum of all elements in a given nested list.
Example Input: [[1, 2], [3, 4], [5, 6]]
Expected Output: 21
-
Write a program to find the number of elements in a given dictionary.
Example Input: {'a': 1, 'b': 2, 'c': 3}
Expected Output: 3
-
Write a program to find the number of uppercase letters in each word of a given sentence.
Example Input: "Python is AWESOME"
Expected Output: 2 1 7
-
Write a program to find the sum of all prime numbers in a given list.
Example Input: [2, 3, 4, 5, 6, 7]
Expected Output: 17
-
Write a program to find the number of lowercase letters in each word of a given sentence.
Example Input: "Python Programming is Fun"
Expected Output: 6 8 2 3
-
Write a program to find the number of even and odd numbers in a given list.
Example Input: [1, 2, 3, 4, 5]
Expected Output: Even: 2 Odd: 3
-
Write a program to find the number of elements that are divisible by a given number in a given set.
Example Input: {1, 2, 3, 4, 5}, 2
Expected Output: 2
-
Write a program to find the sum of all elements in a given dictionary excluding some keys.
Example Input: {'a': 1, 'b': 2, 'c': 3}, ['a', 'c']
Expected Output: 2
-
Write a program to count the number of elements that are divisible by a given number in a given matrix.
Example Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3
Expected Output: 3
-
Write a program to create a new list containing the squared values of the elements of a given list.
Example Input: [1, 2, 3, 4, 5]
Expected Output: [1, 4, 9, 16, 25]
-
Write a program to count the number of elements in a given list that are greater than the average.
Example Input: [1, 2, 3, 4, 5]
Expected Output: 2
-
Write a program to find the sum of all values in a given dictionary.
Example Input: {'a': 1, 'b': 2, 'c': 3}
Expected Output: 6
-
Write a program to find the largest difference between two consecutive elements in a given list.
Example Input: [5, 2, 8, 4, 9]
Expected Output: 6
-
Write a program to check if all elements in a given list are positive.
Example Input: [1, 2, 3, -4, 5]
Expected Output: No
-
Write a program to find the number of words in a given string starting with a vowel.
Example Input: "Apple is a fruit"
Expected Output: 2
-
Write a program to check if all elements in a given list are negative.
Example Input: [-1, -2, -3, -4, -5]
Expected Output: Yes
-
Write a program to find the number of elements in a given list that are greater than a given number.
Example Input: [1, 2, 3, 4, 5], 3
Expected Output: 2
-
Write a program to check if all elements in a given list are unique.
Example Input: [1, 2, 3, 4, 5]
Expected Output: Yes
-
Write a program to find the number of elements in a given list that are less than the average.
Example Input: [1, 2, 3, 4, 5]
Expected Output: 2
-
Write a program to find the number of elements in a given set that are greater than a given number.
Example Input: {1, 2, 3, 4, 5}, 3
Expected Output: 2
-
Write a program to find