Create a base class Vehicle
with attributes make
, model
, and a method display_info()
that prints the make and model. Then, create two subclasses Car
and Motorcycle
that inherit from Vehicle
. Override the display_info()
method in each subclass to display additional information specific to cars and motorcycles.
Define an abstract base class Shape
with an abstract method area()
. Create subclasses Circle
, Rectangle
, and Triangle
that inherit from Shape
. Implement the area()
method in each subclass to calculate and return the area of the respective shapes. Write a function that takes a list of shapes and prints their areas.
Write a program that prompts the user for an integer input. Use a try
and except
block to handle the case where the user enters a non-integer value. Print an error message if the input cannot be converted to an integer.
Write a program that reads a text file and counts the number of occurrences of each word in the file. Create a dictionary where the keys are the words and the values are the counts. Print the dictionary.
Write a function that takes a list of numbers and returns a new list containing only the even numbers. Use the filter()
function along with a lambda function to achieve this.
Implement a simple stack data structure using a Python list. Create methods push()
, pop()
, and peek()
to manipulate the stack. Test your stack by pushing and popping elements.
Design a simple banking system with classes Bank
, Account
, and Transaction
. Create methods for opening accounts, depositing and withdrawing funds, and displaying account details. Use encapsulation and proper design principles.
Write a program that validates email addresses. Prompt the user to enter an email address and check if it matches a valid email pattern using regular expressions.
Create a Python module that defines functions for basic arithmetic operations (addition, subtraction, multiplication, division). Use this module in another script to perform calculations.
Create a list of tuples, each containing a name and an age. Sort the list based on age using the sorted()
function and a lambda function as the key.