Create the class Society
with following information:
society_name
, house_no
, no_of_members
, flat
, income
Methods :
- An
__init__
method to assign initial values ofsociety_name
,house_no
,no_of_members
,income
allocate_flat()
to allocate flat according to income using the below table -> according to income, it will decide to flat typeshow_data()
to display the details of the entire class.- Create one object for each flat type, for each object call
allocate_flat()
andshow_data()
Income | Flat |
---|---|
>=25000 | A Type |
>=20000 and <25000 | B Type |
>=15000 and <20000 | C Type |
<15000 | D Type |
Define a class named ItemInfo
with the following description:
item_code
(Item Code), item
(item name), price
(Price of each item), qty
(quantity in stock), discount
(Discount percentage on the item), net_price
(Price after discount)
Methods :
- A member method
calculate_discount()
to calculate discount as per the following rules: - If
qty <= 10
—> discount is0
- If
qty (11 to 20 inclusive)
—> discount is15
- If
qty >= 20
—> discount is20
- A constructor init method to assign the initial values for
item_code
to0
andprice
,qty
,net_price
anddiscount
tonull
- A function called
buy()
to allow user to enter values foritem_code
,item
,price
,qty
. Then call functioncalculate_discount()
to calculate thediscount
andnet_price
(price * qty - discount). - A function
show_all()
or similar name to allow user to view the content of all the data members.
Create a class called Numbers
, which has a single class attribute called multiplier
, and a constructor which takes the parameters x
and y
(these should all be numbers).
- Write a method called
add
which returns the sum of the attributesx
andy
. - Write a class method called
multiply
, which takes a single number parametera
and returns the product ofa
andmultiplier
. - Write a method called
subtract
, which takes two number parameters,b
andc
, and returnsb - c
. - Write a method called
value
which returns a tuple containing the values ofx
andy
. - Create a numbers object and call all the methods you wrote and print the results.
- Define the
Employee
class with an__init__()
method - Define a class variable
new_id
and set it equal to1
- Each Employee instance will need its own unique ID. Thus, inside
__init__()
, defineself.id
and set it equal to the class variablenew_id
- Lastly, increment
new_id
by1
- Define a
say_id()
method - Inside
say_id()
, output the string"My id is "
and then the instance id. - Define the variable e1 and set it to an instance of Employee
- Define the variable e2 and set it to an instance of Employee
- Have both e1 and e2 output their ids
- Create a
Vehicle
class withname
,max_speed
andmileage
instance attributes - Add function
__str__
to vehicle class and print the info about vehicle as:"Vehicle Model X has max speed 180 and mileage 12"
- Create a child class
Bus
that will inherit all of the variables and methods of theVehicle
class - Add attribute
capacity
to classBus
- Update
Bus
class such that print message will be:Bus Breng has max speed 180 and mileage 50 with capacity 100
(Hint: Override _str_ method) - Add
update_capacity()
method to the classBus
- Create a
Vehicle
and aBus
object and print both of them - call
update_capacity()
method for the earlier createdBus
object and print it, see the difference
-
Inheritance: https://www.hackerrank.com/challenges/inheritance/problem
-
Classes: Dealing with Complex Numbers: https://www.hackerrank.com/challenges/class-1-dealing-with-complex-numbers/problem