Skip to content

AnshDMishra/Python-Programming-Learning-Practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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().

5. WAP to print \t and \n as it is in the output.

Solution

Click Here For Solution

💻 If else Practice Questions

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.

    Click Here For Solution

    💻 Loop Practice Questions

    1. WAP to print all even and odd numbers between 1 and 100;

    2. WAP to print all even and odd numbers between 100 and 1;

    3. WAP to print sum of numbers from 1 and 100;

    4. WAP to print sum of the following series: 12 + 22 + 32+…..+102;

    5. WAP to print calculate the factorial of number entered through keyboard;

    6. WAP to print the following triangle:

               1
               
          2    3
          
    4     5    6
    

    7. WAP to print the following triangle:

               *
               
           *      *
           
        *            *
        
    *    *    *    *     *
    

    8. WAP to print the following triangle:

    1    2    3    4    5
    
    1    2    3    4
    
    1    2    3
    
    1    2
    
    1    
    

    9. WAP to print the following triangle:

         1
    
         2     2  
    
         3     3    3
    
         4     4    4      4
    

    Click Here For Solution

    💻 String Practice Questions

    1. Write a Python program to calculate the length of a string.

    2. Write a Python program to count the number of characters (character frequency) in a string.

    Sample String : google.com' Expected Result : {'o': 3, 'g': 2, '.': 1, 'e': 1, 'l': 1, 'm': 1, 'c': 1}

    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.

    Sample string: "32.054,23" Expected Output: "32,054.23"

    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.

    Click Here For Solution

    💻 List Practice Questions

    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.

    Sample List : ['Red', 'Green', 'White', 'Black', 'Pink', 'Yellow']
    Expected Output : ['Green', 'White', 'Black']

    7. Write a Python program to print the numbers of a specified list after removing even numbers from it.

    8. Write a Python program to convert a list of characters into a string.

    9. Write a Python program to find the second largest number in a list.

    10. Write a Python program to get unique values from a list.

    Click Here For Solution

    💻 Set Practice Questions

    1. Write a Python program to create a set.

    2. Write a Python program to iteration over sets.

    3. Write a Python program to add member(s) in a set.

    4. Write a Python program to remove item(s) from set

    5. Write a Python program to remove an item from a set if it is present in the set.

    6. Write a Python program to create an intersection of sets.

    7. Write a Python program to create a union of sets.

    8. Write a Python program to create set difference.

    9. Write a Python program to create a symmetric difference.

    10. Write a Python program to create a shallow copy of sets.

    11. Write a Python program to clear a set.

    12. Write a Python program to use of frozensets.

    13. Write a Python program to find maximum and the minimum value in a set.

    14. Write a Python program to find the length of a set

    Click Here For Solution

    💻 Dict Practice Questions

    1. Write a Python script to sort (ascending and descending) a dictionary by value.

    2. Write a Python script to add a key to a dictionary

    Sample Dictionary : {0: 10, 1: 20}
    Expected Result : {0: 10, 1: 20, 2: 30}

    3. Write a Python script to concatenate following dictionaries to create a new one.Sample Dictionary :

    dic1={1:10, 2:20}
    dic2={3:30, 4:40}
    dic3={5:50,6:60}
    Expected Result : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

    4. Write a Python script to check if a given key already exists in a dictionary.

    5. Write a Python program to iterate over dictionaries using for loops.

    6. Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x).

    Sample Dictionary ( n = 5) :
    Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

    7. Write a Python script to print a dictionary where the keys are numbers between 1 and 15 (both included) and the values are square of keys.

    Sample Dictionary {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225}

    8. Write a Python script to merge two Python dictionaries.

    9. Write a Python program to iterate over dictionaries using for loops.

    10. Write a Python program to remove a key from a dictionary.

    11. Write a Python program to map two lists into a dictionary.

    12. Write a Python program to sort a dictionary by key.

    13. Write a Python program to remove duplicates(based on values) from Dictionary.

    14. Write a Python program to check a dictionary is empty or not.

    15. Write a Python program to combine two dictionary adding values for common keys.

    d1 = {'a': 100, 'b': 200, 'c':300}
    d2 = {'a': 300, 'b': 200, 'd':400}
    Sample output: Counter({'a': 400, 'b': 400, 'd': 400, 'c': 300})

    16. Write a Python program to print a dictionary in table format.

    17. Write a Python program to get the top three items in a shop.

    Sample data: {'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24} Expected Output:
    item4 55
    item1 45.5
    item3 41.3

    18. Write a Python program to match key values in two dictionaries.

    Sample dictionary: {'key1': 1, 'key2': 3, 'key3': 2}, {'key1': 1, 'key2': 2}
    Expected output: key1: 1 is present in both x and y

    Click Here For Solution

    💻 Function Practice Questions

    1. Write the function to find that entered number even or odd.

    2. Write the function to print the entered number in reverse order.

    3. Write the function to find out whether entered number is prime or not.

    4. Write the function to calculate the factorial of a entered number.

    5. Write the function to print the Fibonacci series. The number of terms for Fibonacci series will be entered through keyboard.

    6. Write the function to find entered number through keyboard is whether Armstrong or not.

    7. Write a function to find entered number through keyboard is whether palindrome or not.

    8. Write a function that takes a number entered through keyboard and find whether it is positive or negative.

    9. Write a function that takes a number entered through keyboard and find whether it isArmstrong number or not.

    10. Write a function that takes two numbers entered through keyboard and return greatest of them.

    11. Write a function that takes numbers entered through keyboard and return the sum of digits of entered numbers.

    12. Write a function that takes two numbers a and b, entered through keyboard and return the value of ab.

    Click Here For Solution

    Contributing 💡

    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:--

    Gmail GitHub

    Show some ❤️ by starring ⭐️ some repositories !!

    About

    Python Programing for Learning and Practice in terms of Questions and their Solutions

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published

    Languages