0% found this document useful (0 votes)
16 views4 pages

Adv Python Assignment

Python assignment

Uploaded by

Gnapika Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Adv Python Assignment

Python assignment

Uploaded by

Gnapika Sri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Adabala Devi aT pense Aduon cect Python Assignment ——__Aauisssut2t- write Q python program and check Tf the given numec~| 'S happy & not Progra: def is happy tn): vem =sumso, While Cnum >0): Tem =nuerth 10 SUM = rem #49 numll =10 rau tit return sum NAM =tot Craputt)) wvt5 = num, ionile Cres) = sand ves}=u): ves cishappylres) eres 224): Pat C* happy number"): Elif Cres ==y)! “Print C'not a happy number"). Output: 35 fappy number what are the Oops Concepts 17 python Explarnaul OOPS Concepts with examples | Object @riented PGTAa Ming Coop) 1S @ programming poradigm that focuses or madeting veal works entities as abjects and defining their Behavior through classes and methods letasses QNd Objects? A class 15 A bfueprint Ortemplate that defines the Structure and eehator of objects: is Pnstance Gf aclass: An object ex Class “Deg: deg --1rit- -C5elf,namne,age): Self. name =name- Seifratage =agé def bank (self): : Print Coot"): dog 1 = Dog CBuddy", 3) Print Cologt. name) “Print (ologs.age) dogs. bankc ). Output: “Buddy Dot : Encapsulation is the bun dling Of \Encapsutation: 21 and ates On that ata cata and methods that 6Pe% | within a Sigle unit: | dx: class Student: def ~-init--CSelfyname): Stlfuname sname def Get-name Gself): return Self. ~ name Student 1 ~ student lMice") “Prat (student 1, get_namet )). Qutput: Alice. & Inheritence: Inheritence Allows Class Csubclassfio inherit Qttributes and methods from Qnother class Couper class). It promotes code ruse and Riterarchical relationshi: PS between classes: ex: class Animal: . def ~-tnit-- Ceelf, specias): Self. Species =spectes def -nake -s0und Cselt): “POSS Class Dog Canimat): def - ~init-- (self, breed): Supent ). —-fnit —~-C Deg"). sett. bread = bread deft .make-sound Gelf): Print Cwwoof!"). dog = peg C'Golden Rebiever") Print (dog. species) dog:make sounde ). | Ovtmet: D4 woof) | Polymorphism: Tt akwws objects Of different classes \4o be treated as Objects Af QA common Superclass . Tt Enables the samc method to behave ditfererrtly based onthe objects actual class (Ox cla% shape: def anea lself): Yretwino Class SqQuane Cshape): def —-fnit — -Csetf, side)‘ S4lf, Side -side def anea (self): def Quea Csetf¢): veturn self, side ¥ Self. Side; class Circle Cshape): def init__(self radius): Self radius =radius . def anea (seit): return sy * Self- radius* Self vadhas SqQuane = squane 5) ; ctrele = circlecs)’ : Print (square .aneac)) Print Céirele “a1eal)) 85 28126 Output: Abstraction: Abstractionisthe proces 5 of simplifying Complex systems by Providing a clear interface for Interaction Abstraction is achieved! through ‘the use Of Abstract classes and interfaces from abc import ABC, abstract method class shape Cec): @ abstractmethed def aneal seg): Pass CLASS sQUCHE Cohape): deP__intit_ -Cself, side): Selt, Side = side def auea self): vetwin sett . side FSPLL, side’ SQuase =SQuanels) Printl square, aeac)) Output 325

You might also like