0% found this document useful (0 votes)
5 views1 page

Python Class Design and Functions Guide

Uploaded by

sahinpradhan850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Python Class Design and Functions Guide

Uploaded by

sahinpradhan850
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Assignment 3

1. Create a class ATM with attributes: balance, and methods: deposit, withdraw, and
show_balance. Add validation so that withdrawal fails if the balance is insufficient, and
implement a transaction history feature.

2. Write a class ShapeOperations with methods like area_circle, area_square, etc. Write
another method get_area(shape, *args) that dynamically calls the corresponding
method based on the value of shape.

3. Design a class Product with subclasses Book, Electronics, and Grocery. Each should
have a method to calculate discount. Create a class Cart that uses a function to apply
discounts and compute total price dynamically.

4. Base class Student holds name and ID. Subclass ExamStudent adds marks, and
ProjectStudent adds project score. Write a method calculate_grade() in both. Use
super() to demonstrate shared logic.

5. Write a recursive function conditional_reverse(s) that reverses a string but keeps all
digits at the same position.
For example:
Input: "a1b2c3"
Output: "c1b2a3"
Remark: Digits (1, 2, 3) must stay where they are — in their original
[Link] rest (a, b, c) are reversed, while digits are untouched.

You might also like