Monday, August 12, 2024

PYTHON PRACTICE QUESTIONS

 

  1. Write a program that checks if a number is even or odd using the modulo operator and an if-else statement.
  2. Create a loop that prints the first 10 multiples of 3.
  3. Use a nested loop to print a simple pattern of asterisks (e.g., a right-angled triangle).
  4. Write a program that uses the break statement to exit a loop when a specific condition is met.
  5. Implement a simple calculator that performs basic arithmetic operations based on user input.                                                                                                                              #PROBLEMS ON FUNCTIONS

6.  Write a function that takes two numbers as arguments and returns their sum, difference, product, and quotient.

7.  Create a function with default arguments that calculate the area of a rectangle.

8.  Write a lambda function that returns the square of a number, and use it in a list comprehension to square all numbers in a given list.

9.  Implement a function that uses *args to find the maximum number among the arguments passed.

#PROBLEMS ON STRINGS

10. Write a program that reverses a string without using the built-in reverse function.

11. Create a function that counts the number of vowels in a given string.

12. Implement a program that checks if a string is a palindrome.

13. Write a function that capitalizes the first letter of each word in a sentence.

14. Create a program that removes all punctuation from a given string.

#LIST OPERATIONS

  1. Write a function that removes duplicates from a list without using set().

  2. Implement a program that finds the second largest number in a list.

  3. Create a function that merges two sorted lists into a single sorted list without using the sort() method.

  4. Write a program that rotates the elements of a list to the right by k steps.

  5. Implement a function that finds all pairs of integers in a list whose sum is equal to a given target.#

  • Tuple and its Operations
  1. Create a program that converts a list of tuples into a dictionary.
  2. Implement a function that finds the index of the maximum value in a tuple of numbers.
  3. Write a program that sorts a list of tuples based on the second element of each tuple.
  4. Create a function that zips two tuples together into a list of tuples.
  5. Write a function that returns the frequency of each element in a tuple.

Sets and Dictionaries

  1. Write a function that finds the symmetric difference between two sets.

  2. Implement a program that counts the frequency of words in a given text using a dictionary.

  3. Create a function that merges two dictionaries, summing the values of common keys.

  4. Write a program that finds the key with the maximum value in a dictionary.

  5. Implement a nested dictionary to represent a simple address book and write functions to add, delete, and search for contacts.

 

No comments:

Post a Comment

PYTHON PRACTICE QUESTIONS

  Write a program that checks if a number is even or odd using the modulo operator and an if-else statement. Create a loo...