What's new

Help Python?

ChaseX

Eternal Poster
Joined
Jan 5, 2022
Posts
518
Solutions
2
Reaction
1,770
Points
329
make atleast 5 python program using classes and object, pwede penge kahit isa or dalawang sample ganon tapos explore ko nalang.
salamat sa makakatulong di kasi nagtuturo teacher namin :ROFLMAO:
 
Python:
class Google:
    def __init__(self, query):
        self.query = query
    
    def search(self):
        print("Searching for query", self.query)
 
google = Google(query="How to write basic class and objects in python")
google.search()
 
Python:
class Lodi:
     mygreeting =    "I Love You! <3"
     def __init__(self, name, age, zodiac):
         self.name = name
         self.age =    age
         self.zodiac =    zodiac
     def crushnow(self):
            return "She is my  crush now!"
      
     def message(self):
            return  Lodi.mygreeting


crush1 =    Lodi("Bbibi", 24, "Pisces")

print(crush1.crushnow())

print(f"Name: {crush1.name}")
print(f"Age: {crush1.age}")
print(f"Zodiac sign: {crush1.zodiac}")

mymessage =    crush1.message()

print(mymessage)

Python:
class Lodi:
     mygreeting =    "I Love You! <3"
     def __init__(self, name, age, zodiac):
         self.name = name
         self.age =    age
         self.zodiac =    zodiac
     def crushnow(self):
            return "She is my  crush now!"
     
     def message(self):
            return  Lodi.mygreeting


crush1 =    Lodi("Bbibi", 24, "Pisces")

print(crush1.crushnow())

print(f"Name: {crush1.name}")
print(f"Age: {crush1.age}")
print(f"Zodiac sign: {crush1.zodiac}")

mymessage =    crush1.message()

print(mymessage)
I'm not a pro 😁 ... Still learning this Language ... 🤗
 

Attachments

Last edited:
Code:
class Guest:
    pass

g_1 = Guest()

g_1.first = "Eve"
g_1.last = "Dela Cruz"
g_1.interest = "Anime"
g_1.phone = 12345

print(g_1.interest)

g_2 = Guest()

g_2.first = "Adam"
g_2.last = "Perez"
g_2.interest = "Russian literature"
g_2.phone = 87654

print(g_2.phone)

print(g_1.first,g_1.last,"and",g_2.first,g_2.last)
 
Back
Top