Python Programming Problems: Functions, OOP, and Loops
1. Loops - Coding Problems
1. Write a program to print all prime numbers between 1 and 100.
2. Write a program to print a right-angled triangle pattern using stars.
3. Write a program to calculate the factorial of a number using a loop.
4. Write a program to reverse a string using a loop.
5. Write a program to find the sum of digits of a number.
6. Write a program to find the GCD of two numbers using a loop.
7. Write a program to generate the Fibonacci series up to n terms using a loop.
8. Write a program to check if a number is an Armstrong number.
9. Write a program to count vowels and consonants in a string using a loop.
10. Write a program to find the largest and smallest number in a list using a loop.
11. Write a program to display a multiplication table using nested loops.
12. Write a program to find common elements in two lists using loops.
13. Write a program to remove duplicates from a list using loops.
14. Write a program to display even and odd numbers from a list using loops.
15. Write a program to count the frequency of each character in a string using loops.
16. Write a program to find the second largest number in a list using loops.
17. Write a program to check if a list is sorted using a loop.
18. Write a program to shift elements of a list circularly using a loop.
19. Write a program to merge two lists using loops.
20. Write a program to rotate a matrix 90 degrees using loops.
2. Functions - Coding Problems
1. Write a function to find the factorial of a number.
2. Write a function to check if a number is a palindrome.
3. Write a function to calculate the sum of squares of first n natural numbers.
4. Write a function that takes a list and returns the maximum value.
5. Write a recursive function to calculate the nth Fibonacci number.
6. Write a function to check whether a string is a pangram.
7. Write a function that returns the count of even and odd numbers in a list.
8. Write a function to convert Celsius to Fahrenheit.
9. Write a function that accepts a string and returns the number of vowels.
10. Write a function that returns True if a number is prime, else False.
11. Write a function that takes variable number of arguments and returns their sum.
12. Write a lambda function to sort a list of tuples by the second item.
13. Write a function to merge two dictionaries.
14. Write a function to return a dictionary with word counts from a string.
15. Write a function that returns the longest word in a sentence.
3. Object-Oriented Programming (OOP) - Coding Problems
1. Create a class `Person` with attributes `name` and `age`, and a method to display them.
2. Create a class `BankAccount` with deposit and withdraw methods.
3. Create a class `Rectangle` that calculates area and perimeter.
4. Create a class `Student` with a method to calculate average marks from a dictionary.
5. Create a class `Car` with attributes `make`, `model`, and `year`, and a method to display info.
6. Create a class `Circle` with method to calculate area and circumference.
7. Implement inheritance with a base class `Animal` and derived classes `Dog` and `Cat`.
8. Create a class that overloads the `+` operator to add two vectors.
9. Create a class that overrides the `__str__` method for pretty printing.
10. Create a class with a static method to validate an email address.
11. Create a class with class variables and instance variables, and demonstrate their difference.
12. Create a class `Employee` and count the number of employees created using class variable.
13. Create a class with a property that returns the square of a number.
14. Implement polymorphism using method overriding with base and derived classes.
15. Create a class with private members and access them using getter and setter methods.