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_codeto0andprice,qty,net_priceanddiscounttonull - A function called
buy()to allow user to enter values foritem_code,item,price,qty. Then call functioncalculate_discount()to calculate thediscountandnet_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
addwhich returns the sum of the attributesxandy. - Write a class method called
multiply, which takes a single number parameteraand returns the product ofaandmultiplier. - Write a method called
subtract, which takes two number parameters,bandc, and returnsb - c. - Write a method called
valuewhich returns a tuple containing the values ofxandy. - Create a numbers object and call all the methods you wrote and print the results.
- Define the
Employeeclass with an__init__()method - Define a class variable
new_idand set it equal to1 - Each Employee instance will need its own unique ID. Thus, inside
__init__(), defineself.idand set it equal to the class variablenew_id - Lastly, increment
new_idby1 - 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
Vehicleclass withname,max_speedandmileageinstance 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
Busthat will inherit all of the variables and methods of theVehicleclass - Add attribute
capacityto classBus - Update
Busclass 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
Vehicleand aBusobject and print both of them - call
update_capacity()method for the earlier createdBusobject 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