0% found this document useful (0 votes)
3 views2 pages

Day7 Assignment MethodTypes

The document outlines an assignment for a Python Masterclass focusing on Object-Oriented Programming methods, including instance, class, and static methods. It consists of 12 questions divided into three sections, each requiring the creation of specific classes and methods with detailed instructions for implementation and testing. The final submission should include well-commented code, outputs, and be formatted in a Python file named 'Day7_Assignment_MethodTypes_.py'.
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)
3 views2 pages

Day7 Assignment MethodTypes

The document outlines an assignment for a Python Masterclass focusing on Object-Oriented Programming methods, including instance, class, and static methods. It consists of 12 questions divided into three sections, each requiring the creation of specific classes and methods with detailed instructions for implementation and testing. The final submission should include well-commented code, outputs, and be formatted in a Python file named 'Day7_Assignment_MethodTypes_.py'.
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

Python Masterclass – Day 7 Assignment

Topic: Types of Methods in OOP (Instance, Class, and Static


Methods)
Instructions:
1 Write Python code for each question in a separate cell or file.
2 Add comments explaining each line wherever necessary.
3 Show the output and ensure the logic is properly tested.
4 Avoid reusing examples from the lecture; create fresh logic as per question
requirement.

A. Instance Methods (4 Questions)


1 Q1. Create a Student class with attributes name and marks. Write an instance method
grade() that returns 'Pass' if marks ≥ 40 else 'Fail'. Use this method for 3 different
student objects and display their result.

2 Q2. Design a BankAccount class with attributes holder_name and balance. Implement
deposit(amount) and withdraw(amount) instance methods. Display the final balance
after a series of transactions.

3 Q3. Create a Rectangle class with attributes length and width. Add area() and
is_square() methods to check if both sides are equal. Demonstrate both methods with
multiple objects.

4 Q4. Write a Product class having attributes name, price, and discount. Add
final_price() to calculate discounted price. Ask user input for details of three products
and print their final prices.

B. Class Methods (4 Questions)


1 Q5. Create a Company class with class attribute company_name = 'TechVerse'.
Define change_company_name(new_name) class method to modify it and show
reflection in all objects.

2 Q6. Design a Laptop class with attributes brand and price. Use class variable tax =
0.10. Create class method set_tax(new_tax) to update tax and display final price
before and after change.

3 Q7. Create a Car class with attributes brand and mileage. Add class variable fuel_type
= 'Petrol'. Add update_fuel_type(new_type) to change fuel type for all cars.
Demonstrate with multiple objects.

4 Q8. Create a Book class with class attribute total_books = 0. Each time a new book
object is created, increase count using class method increment_books(). Display total
books after adding 5 objects.

C. Static Methods (4 Questions)


1 Q9. Create a MathUtility class having is_even(number) static method that returns True
if even, False otherwise. Demonstrate using a list of numbers.

2 Q10. Design a Temperature class with static method c_to_f(celsius) to convert Celsius
to Fahrenheit. Demonstrate conversion for three values.

3 Q11. Write a PasswordValidator class with static method validate(password) checking:


minimum 8 chars, one uppercase, one lowercase, one digit. Return 'Strong Password'
or 'Weak Password'.

4 Q12. Create a StringTools class with is_palindrome(word) static method that checks if
a word is palindrome. Demonstrate with 3 different strings.

Submission Format:
File Name: Day7_Assignment_MethodTypes_.py
Include both code and output. Make sure each question is commented, well-formatted,
and tested.

You might also like