From f237a6c5feada7f994b260a6a326d5345e976a8f Mon Sep 17 00:00:00 2001 From: Ramaguru Radhakrishnan <7790256+ramagururadhakrishnan@users.noreply.github.com> Date: Sun, 24 Dec 2023 15:02:12 +0530 Subject: [PATCH] Updated - Python Code - Removed unnecessary space --- Materials/README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Materials/README.md b/Materials/README.md index a65d99e..a9d86a4 100644 --- a/Materials/README.md +++ b/Materials/README.md @@ -2,7 +2,7 @@ ![](https://img.shields.io/badge/Batch-22CYS-lightgreen) ![](https://img.shields.io/badge/UG-blue) ![](https://img.shields.io/badge/Subject-AdP-blue) ![](https://img.shields.io/badge/-HPOJ-brown) -## Object Oriented Programming +## Object Oriented Programming - Comparison with C Program ### C Progarm @@ -83,4 +83,34 @@ int main() { } ``` +### Python Program + +car.py +``` +class Car: + def __init__(self): + self.make = "" + self.model = "" + self.year = 0 + self.price = 0.0 + + # Method to display car details + def displayDetails(self): + print("Car Details:") + print("Make:", self.make) + print("Model:", self.model) + print("Year:", self.year) + print("Price: ${:.2f}".format(self.price)) + +# Creating an object of the Car class +myCar = Car() + +# Setting attributes for the car object +myCar.make = "Jaguar" +myCar.model = "XF" +myCar.year = 2022 +myCar.price = 7160000.00 + +# Calling the method to display car details +myCar.displayDetails() ```