Problem based on object oriented concept-4/8/2023

  1. Write a Python program to create a class representing a shopping cart. Include methods for adding and removing items, and calculating the total price.

  2. Write a Python program to create a class that represents a shape. Include methods to calculate its area and perimeter. Implement subclasses for different shapes like circle, triangle, and square.

  3. Create a child class Bus that will inherit all of the variables and methods of the Vehicle class.

4.Define a class which has at least two methods:getString:1) to get a string from console input,
2)print String: to print the string in upper case.
Also please include simple test function to test the class methods

  1. A website requires the users to input username and password to register. Write a program to check the validity of password input by users.
    Following are the criteria for checking the password:
    1. At least 1 letter between [a-z]
    2. At least 1 number between [0-9]
    1. At least 1 letter between [A-Z]
    3. At least 1 character from [$#@]
    4. Minimum length of transaction password: 6
    5. Maximum length of transaction password: 12
    Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma.
    If the following passwords are given as input to the program:
    ABd1234@1,a F1#,2w3E*,2We3345
    Then, the output of the program should be:

6.Define a class, which have a class parameter and have a same instance parameter.

7.Consider the following code:
class Spell(object):
def init(self, incantation, name): = name
self.incantation = incantation
def str(self):
return + ’ ’ + self.incantation + ’\n’ + self.get_description()
def get_description(self):
return ’No description’
def execute(self):
print self.incantation
class Accio(Spell):
def init(self):
Spell.init(self, ’Accio’, ’Summoning Charm’)
class Confundo(Spell):
def init(self):
Spell.init(self, ’Confundo’, ’Confundus Charm’)
def get_description(self):
return ’Causes the victim to become confused and befuddled.’
def study_spell(spell):
print spell
spell = Accio()

            1. What are the parent and child classes?
            2. What does the code print out? (Try figuring it out without running it in Python first)
            3. Which get description method is called when ‘study spell(Confundo())’ is executed? Why?
            4. What do we need to do so that ‘print Accio()’ will print the appropriate description?
            Accio Summoning Charm
            This charm summons an object to the caster, potentially over a significant distance.
            Write down the code that we need to add and/or change.