Python_Practice_Questions
Python_Practice_Questions
10. Write a Python program to compare three numbers and print them in ascending order.
Loops
1. Print the first 10 natural numbers using a while loop.
2. Display numbers from a list using a loop.
3. Display numbers from -10 to -1 using a for loop.
4. Print the multiplication table of a given number.
5. Print a list in reverse order using a loop.
6. Display a message 'Done' after successful execution of a for loop.
Mathematical Operations
1. Calculate the sum of all numbers from 1 to a given number.
2. Calculate the cube of all numbers from 1 to a given number.
3. Find the factorial of a given number.
4. Print all prime numbers within a specified range.
5. Display the Fibonacci series up to 10 terms.
6. Reverse an integer number.
7. Find the sum of the series up to n terms.
Patterns
1. Print the following number pattern using nested loops:
1
22
333
4444
2. Write a Python program to construct the following pattern using a nested loop:
*
**
***
3. Write a Python program to create the multiplication table of a given number:
6x1 = 6
6x2 = 12
6x3 = 18
…
4. Write a Python program to construct the following pattern using a nested loop:
*
**
***
****
*****
****
***
**
*
Functions
1. Create a function in Python.
2. Create a function with variable-length arguments.
3. Return multiple values from a function.
4. Create a function with a default argument.
5. Create an inner function to calculate the addition.
6. Create a recursive function.
7. Assign a different name to a function and call it.
8. Generate a Python list of all even numbers between 4 to 30.
String Operations
1. Create a string made of the first, middle, and last character of a string.
2. Create a string made of the middle three characters of a string.
3. Split a string on hyphens.
4. Find the last position of a given substring in a string.
5. Replace each special symbol with # in a given string.
6. Count all letters, digits, and special symbols from a given string.
7. Create a mixed string using rules where characters from two strings alternate.
8. Test if two strings are balanced (all characters of one string are in the other).
9. Find all occurrences of a substring in a given string, ignoring case.
10. Calculate the sum and average of digits present in a string.
11. Write a program to count occurrences of all characters in a string.
12. Reverse a given string.
13. Remove special symbols/punctuation from a string.
14. Remove all characters from a string except integers
List Operations
1. Print list in reverse order using a loop.
2. Display numbers from -10 to -1 using a for loop.
3. Reverse a list in Python.
4. Concatenate two lists index-wise.
5. Turn every item of a list into its square.
6. Remove all occurrences of a specific item from a list.
7. Add a new item to a list after a specified item.
8. Concatenate two lists in the following order.
9. Iterate both lists simultaneously.
10. Extend a nested list by adding a sublist.
11. Replace a list’s item with a new value if found.
12. Print elements from a given list present at odd index positions.
13. Calculate the cube of all numbers from 1 to a given number.
14. Remove empty strings from the list of strings.
Tuple Operations
1. Reverse a tuple.
2. Access the value 20 from a tuple.
3. Unpack a tuple into four variables.
4. Count the number of occurrences of item 50 in a tuple.
Dictionary Operations
1. Convert two lists into a dictionary.
2. Merge two Python dictionaries into one.
3. Print the value of key 'history' from a given dictionary.
4. Rename a key in a dictionary.
5. Initialize a dictionary with default values.
6. Create a dictionary by extracting specific keys from another dictionary.
7. Delete a list of keys from a dictionary.
8. Check if a value exists in a dictionary.
9. Get the key of the minimum value from a given dictionary.
10. Change the value of a key in a nested dictionary.
Set Operations
1. Add a list of elements to a set.
2. Return a new set of identical items from two sets.
3. Check if two sets have any elements in common and display them.
4. Get only unique items from two sets.
5. Update the first set with items that don’t exist in the second set.
6. Remove multiple items from a set at once.
7. Return a set of elements present in Set A or Set B but not both.
8. Update set1 by adding items from set2, except for common items.
9. Remove items from set1 that are not common to both set1 and set2.