w3resource
w3resource logo
Python Exercises

Python Basic(Part-II) - Exercises, Practice, Solution

Python basic (Part-II) [17 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts.]

1. Write a Python function that takes a sequence of numbers and determines if all the numbers are different from each other. Go to the editor
Click me to see the sample solution

2. Write a Python program to create all possible strings by using 'a', 'e', 'i', 'o', 'u'. Use the characters exactly once. Go to the editor
Click me to see the sample solution

3. Write a Python program to remove and print every third number from a list of numbers until the list becomes empty.
Click me to see the sample solution

4. Write a Python program to find unique triplets whose three elements gives the sum of zero from an array of n integers. Go to the editor
Click me to see the sample solution

5. Write a Python program to create the combinations of 3 digit combo. Go to the editor
Click me to see the sample solution

6. Write a Python program to print a long text, convert the string to a list and print all the words and their frequencies. Go to the editor
Click me to see the sample solution

7. Write a Python program to count the number of each character of a given text of a text file. Go to the editor
Click me to see the sample solution

8. Write a Python program to get the top stories from Google news. Go to the editor
Click me to see the sample solution

9. Write a Python program to get a list of locally installed Python modules. Go to the editor
Click me to see the sample solution

10. Write a Python program to display some information about the OS where the script is running. Go to the editor
Click me to see the sample solution

11. Write a Python program to check the sum of three elements (each from an array) from three arrays is equal to a target value. Print all those three-element combinations. Go to the editor
Sample data:
/*
X = [10, 20, 20, 20]
Y = [10, 20, 30, 40]
Z = [10, 30, 40, 20]
target = 70
*/
Click me to see the sample solution

12. Write a Python program to create all possible permutations from a given collection of distinct numbers.Go to the editor
Click me to see the sample solution

13. Write a Python program to get all possible two digit letter combinations from a digit (1 to 9) string. Go to the editor
string_maps = {
"1": "abc",
"2": "def",
"3": "ghi",
"4": "jkl",
"5": "mno",
"6": "pqrs",
"7": "tuv",
"8": "wxy",
"9": "z"
}
Click me to see the sample solution

14. Write a Python program to add two positive integers without using the '+' operator. Go to the editor
Note: Use bitwise operations to add two numbers.
Click me to see the sample solution

15. Write a Python program to check the priority of the four operators (+, -, *, /). Go to the editor
Click me to see the sample solution

16. Write a Python program to get the third side of right angled triangle from two given sides. Go to the editor
Click me to see the sample solution

17. Write a Python program to get all strobogrammatic numbers that are of length n. Go to the editor
A strobogrammatic number is a number whose numeral is rotationally symmetric, so that it appears the same when rotated 180 degrees. In other words, the numeral looks the same right-side up and upside down (e.g., 69, 96, 1001).
For example,
Given n = 2, return ["11", "69", "88", "96"].
Given n = 3, return ['818', '111', '916', '619', '808', '101', '906', '609', '888', '181', '986', '689']

Click me to see the sample solution

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Amazon promo codes to get huge discounts for limited period (USA only).