Python Programming (Learning & Practice Questions)
π» Basic "Print" π»
1. Write a Python program to print the following string in a specific format (see the output).
Output :
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a diamond in the sky.
Twinkle, twinkle, little star,
How I wonder what you are
2. WAP to print names of your 5 friends each in new line using single print() and single string.
3. WAP to print names of your 5 friends each in new line using single print() and independent string for each name.
4. WAP to print names of your 5 friends each in new line using 5 print().
1. An Integer is Input through keyboard. Write a program to find whether it is odd or even number.
2. If cost price and selling price of an item is input through keyboard. Write a program to determine how much profit he made or how much loss he got.
3. WAP to test a number is divisible by 3 or 5 and both.
4. WAP to find the greatest of three numbers entered through keyboard.
5. The marks obtain by a student in 5 different subjects are input through keyboard. The student gets the division as per the following rules:
Percentage above or equal to 60- first division
Percentage between 50 and 59- second division
Percentage between 40 and 49 β third division
Percentage below 40- fails.
6. Admission to professional course in a college according to following conditions:
Marks in Mathematics are greater than or equal to 60 and marks in physics is greater than or equal to 50 and marks in chemistry is greater than or equal to 40
OR
Total marks in mathematics, physics and chemistry is greater than or equal to 200.
OR
Total marks in mathematics and physics are greater than or equal to 150.
Marks of all three subjects will be entered through the keyboard. WAP to tell whether a student is qualifying for admission or not.
7. Write a program that has following menu:
Enter 1 to find the area of rectangle.
Enter 2 to find the area of circle.
Values for length and width of a rectangle and value of a radius of circle will be entered through keyboard.
8. Write a program that has following menu:
Enter 1 to find out whether the entered number is even or odd.
Enter 2 to find out whether the entered number is positive or negative.
9. WAP that implements the simple calculator that has following menu:
Enter 1 to find the addition of two numbers.
Enter 2 to find the subtraction of two numbers.
Enter 3 to find the multiplication of two numbers.
Enter 4 to find the division of two numbers.
Enter 5 to find the inverse of a number.
Enter 6 to find the square of a number.
Enter 7 to find the cube of a number.
10. Write a program that has following menu:
Enter code w for withdraw.
Enter code d for deposit.
Enter code c for checking balance.
Note: You can withdraw an amount only if balance is greater than or equal to 500 and withdrawing amount should be less than balance.
3. Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.
Sample String : 'restart'
Expected Result : 'resta$t'
4. Write a Python program to get a single string from two given strings, separated by a space and swap the first two characters of each string.
Sample String : 'abc', 'xyz'
Expected Result : 'xycabz'
5. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is less than 3, leave it unchanged.
Sample String : 'abc'
Expected Result : 'abcing'
Sample String : 'string'
Expected Result : 'stringly'
6. Write a Python program to find the first appearance of the substring 'not' and 'poor' from a given string, if 'not' follows the 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the resulting string.
Sample String : 'The lyrics is not that poor!'
'The lyrics is poor!'
Expected Result : 'The lyrics is good!'
'The lyrics is poor!'
7. Write a Python function that takes a list of words and returns the length of the longest one.
8. Write a Python program to change a given string to a new string where the first and last chars have been exchanged.
9. Write a Python program to remove the characters which have odd index values of a given string.
10. Write a Python program to count the occurrences of each word in a given sentence.
11. Write a Python script that takes input from the user and displays that input back in upper and lower cases.
12. Write a Python program that accepts a comma separated sequence of words as input and prints the unique words in sorted form (alphanumerically).
Sample Words : red, white, black, red, green, black
Expected Result : black, green, red, white,red
13. Write a Python function to insert a string in the middle of a string.
14. Write a Python function to get a string made of 4 copies of the last two characters of a specified string (length must be at least 2).
Sample function and result :
insert_end('Python') ->onononon
insert_end('Exercises') ->eseseses
15. Write a Python function to get a string made of its first three characters of a specified string. If the length of the string is less than 3 then return the original string.
Sample function and result :
first_three('ipy') ->ipy
first_three('python') ->pyt
16.Write a Python program to get a char in a string just before specified substring.
17. Write a Python function to reverses a string if it's length is a multiple of 4.
18. Write a Python function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.
19.Write a Python program to sort a string lexicographically.
20. Write a Python program to remove all newlines in a string.
21. Write a Python program to check whether a string starts with specified characters
22. Write a Python program to count occurrences of a substring in a string.
23. Write a Python program to reverse a string.
24. Write a Python program to reverse words in a string.
25. Write a Python program to strip a set of characters from a string
26. Write a Python program to count repeated characters in a string.
Sample string: 'thequickbrownfoxjumpsoverthelazydog'
Expected output :
o 4
e 3
u 2
h 2
r 2
t 2
27. Write a Python program to print the index of the character in a string
28. Write a Python program to check if a string contains all letters of the alphabet.
29. Write a Python program to convert a string in a list.
30. Write a Python program to lowercase first n characters in a string.
31. Write a Python program to swap comma and dot in a string.
32. Write a Python program to count and display the vowels of a given text.
33. Write a Python program to split a string on the last occurrence of the delimiter(space).
34. Write a Python program to find the first non-repeating character in given string.
35. Write a Python program to print all permutations with given repetition number of characters of a given string.
36. Write a Python program to find the first repeated character in a given string.
37. Write a Python program to find the first repeated character of a given string where the index of first occurrence is smallest.
38.Write a Python program to find the first repeated word in a given string.
39. Write a Python program to find the second most repeated word in a given string.
40.Write a Python program to remove spaces from a given string.
41. Write a Python program to move spaces to the front of a given string.
42. Write a Python program to find the maximum occurring character in a given string.
43. Write a Python program to capitalize first and last letters of each word of a given string.
44. Write a Python program to remove duplicate characters of a given string.
45.WAP to find whether string entered from keyboard contains the character βaβ or not.
46.WAP to find number of occurrences of character βoβ in the string entered through keyboard. If the character βoβ is not present in the string then show a message βo is not present in the entered stringβ.
47.WAP which read a string from keyboard and print it in reverse order.
48.WAP which read the string and print only vowel characters of entered string on computer screen.
49.WAP that reads a string from keyboard and determine whether the string is palindrome or not.
50.WAP to delete all vowel from a sentence of the character length 15. The sentence should be entered through keyboard.
1. Write a Python program to sum all the items in a list.
2. Write a Python program to get the largest number from a list
3. Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings.
Sample List : ['abc', 'xyz', 'aba', '1221']
Expected Result : 2
4. Write a Python program to remove duplicates from a list.
5. Write a Python program to check a list is empty or not.
6. Write a Python program to print a specified list after removing the 0th, 4th and 5th elements.
If you want to contribute to this project and make it better with new Question and their Solutions, your pull request is most welcomed. If you find any issue just put it in the repository issue section.
or
If you have any suggetions or advice please feel free to connect me:--
Show some β€οΈ by starring βοΈ some repositories !!
About
Python Programing for Learning and Practice in terms of Questions and their Solutions