Leetcode with dani
前往频道在 Telegram
Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts
显示更多1 240
订阅者
-124 小时
-37 天
-1730 天
帖子存档
1 240
try this one Design an OOP solution to represent a library system, including books, authors, and members.
05 12月 2023, 10:52
1 240
Object-Oriented Programming (OOP)
Object-oriented programming (OOP) is a programming paradigm that organizes software around data, or objects, rather than functions and procedures. In OOP, objects are self-contained entities that encapsulate data (attributes) and behavior (methods). They can communicate with each other through a well-defined interface.
Key Concepts in OOP
Class: A class is a blueprint for creating objects. It defines the attributes and methods that all objects of that class will have.
Object: An object is an instance of a class. It represents a specific entity in the real world, such as a person, a dog, or a car.
Instantiation: The process of creating an object from a class is called instantiation.
Inheritance: Inheritance allows classes to inherit attributes and methods from other classes. This enables code reuse and promotes code maintainability.
Encapsulation: Encapsulation is the process of hiding the internal implementation details of an object and exposing only the necessary methods to interact with it. This promotes modularity and protects data integrity.
Benefits of OOP
Modular Code: OOP promotes code modularity by breaking down complex programs into smaller, manageable units called classes.
Reusability: OOP allows for code reuse through inheritance and polymorphism, making development more efficient and cost-effective.
Maintainability: OOP code is easier to maintain and modify due to its modular structure and well-defined interfaces.
Scalability: OOP makes it easier to develop scalable and extensible applications, as new classes can be easily added or modified without affecting existing code.
Creating an Object from a Class
To create an object from a class, use the following syntax:
Python
object_name = ClassName(argument1, argument2, ...)
Use code with caution. Learn more
Where:
object_name is the name of the object you are creating
ClassName is the name of the class you are using to create the object
argument1, argument2, ... are the arguments required by the init() method of the class
Accessing Attributes and Calling Methods
To access an attribute of an object, use the following syntax:
Python
object_name.attribute_name
Use code with caution. Learn more
Where:
object_name is the name of the object
attribute_name is the name of the attribute
To call a method of an object, use the following syntax:
Python
object_name.method_name(argument1, argument2, ...)
Use code with caution. Learn more
Where:
object_name is the name of the object
method_name is the name of the method
argument1, argument2, ... are the arguments required by the method
Example: Modeling a Dog
Let's create a simple class called Dog to model a dog:
Python
class
Dog:
def
init(self, name, age):
self.name = name
self.age = age
def
sit(self):
print(f"{self.name} is sitting.")
def
roll_over(self):
print(f"{self.name} rolled over!")
Use code with caution. Learn more
To create a Dog object, use the following code:
Python
my_dog = Dog('Willie', 6)
Use code with caution. Learn more
Now you can interact with the Dog object using its attributes and methods:
Python
print(my_dog.name) # Output: Willie
my_dog.sit() # Output: Willie is sitting.
my_dog.roll_over() # Output: Willie rolled over!
Use code with caution. Learn more
Conclusion
05 12月 2023, 10:52
1 240
python for intermidiet Object-Oriented Programming (OOP)
Object-oriented programming (OOP) is a programming paradigm that organizes software around data, or objects, rather than functions and procedures. In OOP, objects are self-contained entities that encapsulate data (attributes) and behavior (methods). They can communicate with each other through a well-defined interface.
Key Concepts in OOP
Class: A class is a blueprint for creating objects. It defines the attributes and methods that all objects of that class will have.
Object: An object is an instance of a class. It represents a specific entity in the real world, such as a person, a dog, or a car.
Instantiation: The process of creating an object from a class is called instantiation.
Inheritance: Inheritance allows classes to inherit attributes and methods from other classes. This enables code reuse and promotes code maintainability.
Encapsulation: Encapsulation is the process of hiding the internal implementation details of an object and exposing only the necessary methods to interact with it. This promotes modularity and protects data integrity.
Benefits of OOP
Modular Code: OOP promotes code modularity by breaking down complex programs into smaller, manageable units called classes.
Reusability: OOP allows for code reuse through inheritance and polymorphism, making development more efficient and cost-effective.
Maintainability: OOP code is easier to maintain and modify due to its modular structure and well-defined interfaces.
Scalability: OOP makes it easier to develop scalable and extensible applications, as new classes can be easily added or modified without affecting existing code.
Creating an Object from a Class
To create an object from a class, use the following syntax:
Python
object_name = ClassName(argument1, argument2, ...)
Use code with caution. Learn more
Where:
object_name is the name of the object you are creating
ClassName is the name of the class you are using to create the object
argument1, argument2, ... are the arguments required by the init() method of the class
Accessing Attributes and Calling Methods
To access an attribute of an object, use the following syntax:
Python
object_name.attribute_name
Use code with caution. Learn more
Where:
object_name is the name of the object
attribute_name is the name of the attribute
To call a method of an object, use the following syntax:
Python
object_name.method_name(argument1, argument2, ...)
Use code with caution. Learn more
Where:
object_name is the name of the object
method_name is the name of the method
argument1, argument2, ... are the arguments required by the method
Example: Modeling a Dog
Let's create a simple class called Dog to model a dog:
Python
class
Dog:
def
init(self, name, age):
self.name = name
self.age = age
def
sit(self):
print(f"{self.name} is sitting.")
def
roll_over(self):
print(f"{self.name} rolled over!")
Use code with caution. Learn more
To create a Dog object, use the following code:
Python
my_dog = Dog('Willie', 6)
Use code with caution. Learn more
Now you can interact with the Dog object using its attributes and methods:
Python
print(my_dog.name) # Output: Willie
my_dog.sit() # Output: Willie is sitting.
my_dog.roll_over() # Output: Willie rolled over!
Use code with caution. Learn more
05 12月 2023, 10:50
1 240
Introduction to Data and Variables in Python
In the world of programming, data is the fundamental element used to represent information and solve problems. Python, a versatile and widely used programming language, offers various data types and structures to effectively manage and manipulate data. In this lecture, we will delve into the concepts of data and variables in Python, laying the foundation for your programming journey.
Understanding Data Types
Python provides a variety of data types to represent different kinds of information. These data types can be broadly classified into two categories:
Numeric Data Types: These data types represent numbers, including integers (whole numbers) and floats (numbers with decimal places). Examples include 10, -20, 3.14, and -5.6.
Non-Numeric Data Types: These data types represent non-numeric information, such as text, characters, and Boolean values (True or False). Examples include "Hello World", 'A', and True.
Introducing Variables
Variables are like containers that hold data values. They allow us to store and access data during the execution of a program. Variables have names, which act as labels to identify them.
Naming Conventions for Variables
Python follows certain conventions for naming variables:
Variable names can contain letters, numbers, and underscores.
Variable names should start with a letter or an underscore, not a number.
Spaces are not allowed in variable names, but underscores can be used to separate words.
Avoid using Python keywords and function names as variable names.
Variable names should be descriptive and meaningful.
Assigning Values to Variables
To store a value in a variable, we use the assignment operator =. For example:
Python
age = 25
name = "Alice"
is_active = True
Use code with caution. Learn more
Here, we have assigned the value 25 to the variable age, the string "Alice" to the variable name, and the Boolean value True to the variable is_active.
Accessing Data Stored in Variables
To access the value stored in a variable, we simply use its name. For example:
Python
print(age)
print(name)
print(is_active)
Use code with caution. Learn more
This will print the following output:
25
Alice
True
05 12月 2023, 10:24
1 240
Please join the group i created two groups one for beginners and the other one is for intermediates
03 12月 2023, 01:38
1 240
Repost from 🇪🇹Ethio Apps Store 📀
Learn python pro 🔥
❏ Playstore link
https://play.google.com/store/apps/details?id=python.programming.coding.python3.development
🔆#Python ትምህርት በቀላሉ እና ግልፅ በሆነ መንገድ መማር ከፈለጋችሁ ይሄ አፕ ለናንተ ነው።
❏ Mod info :
● Lifetime access to use
● Ads are removed
● Debug info removed
● Unnecessary code and file are removed
● Fast start up
● Orginal signiture changed to judannah (No need to worry:))
➤ Modded by >@abcdegftabot
🦋#Share🦋
👩💻 @ethioapps1👨💻
30 10月 2023, 05:51
1 240
ቴሌግራማቹን ከአጭበርባሪዎች ይጠብቁ!!!
ቴሌግራም ላይ ከማንኛውም ሰው በ cutt.ly ወይም bit.ly የሚጀምር ማንኛውም ሊንክ ተልኮላችሁ ስታገኙ እንዳትከፍቱት ምክንያቱም ሰሞኑን የመጣ ቫይረስ አለ ሙሉ ለሙሉ የተፃፃፋችሁትን እና Join ያደረጋችሁትን ቻናሎች ሁሉ ያጠፋውና እንደ አዲስ ነው አካውንት ክፈቱ የሚላቹ ይሔ ትልቅ ጥንቃቄ የሚያስፈልገው ነገር ነው ።
እንደዚህ ዓይነት ሊንኮች በምታውቋቸው ሰዎች ስም ጭምር ሊላክላችሁ ይችላል ነገር ግን በጭራሽ እንዳትከፍቱ።
በተጨማሪም ከሀከሮች አካውንታችሁን ለማዳን በምታስታውሱት Password Two-Step Verification On አድርጉ!
#Share በማድረግ ለምታውቁት ሰው ይላኩ!
@Bisrat_sport_433et @Bisrat_sport_433et
27 10月 2023, 12:14
1 240
Repost from 4-3-3 ስፖርት በኢትዮጵያ™
ቴሌግራማቹን ከአጭበርባሪዎች ይጠብቁ!!!
ቴሌግራም ላይ ከማንኛውም ሰው በ cutt.ly ወይም bit.ly የሚጀምር ማንኛውም ሊንክ ተልኮላችሁ ስታገኙ እንዳትከፍቱት ምክንያቱም ሰሞኑን የመጣ ቫይረስ አለ ሙሉ ለሙሉ የተፃፃፋችሁትን እና Join ያደረጋችሁትን ቻናሎች ሁሉ ያጠፋውና እንደ አዲስ ነው አካውንት ክፈቱ የሚላቹ ይሔ ትልቅ ጥንቃቄ የሚያስፈልገው ነገር ነው ።
እንደዚህ ዓይነት ሊንኮች በምታውቋቸው ሰዎች ስም ጭምር ሊላክላችሁ ይችላል ነገር ግን በጭራሽ እንዳትከፍቱ።
በተጨማሪም ከሀከሮች አካውንታችሁን ለማዳን በምታስታውሱት Password Two-Step Verification On አድርጉ!
#Share በማድረግ ለምታውቁት ሰው ይላኩ!
@Bisrat_sport_433et @Bisrat_sport_433et
27 10月 2023, 12:14
1 240
T1=(2,3)
a,b=T1
T2=(b,T1) print(T2) #output=?
09 10月 2023, 09:26
1 240
print(5 ** 2 // 7 == (not(2 // 5 == 5)))
#out put == ?
09 10月 2023, 09:11
1 240
what is th out put of this code?
print(5 ** 2 // 7 == (not(2 // 5 == 5)))
09 10月 2023, 09:05
09 10月 2023, ~09:10
1 240
n=int(input('number:'))
num=0
if n < 0:
n=-n
while n > 0:
no=n%10
if no % 2 != 0:
num+=1
n=n//10
print(num)
09 10月 2023, 02:40
1 240
n=int(input('number:'))
num=0
if n < 0:
n=-n
while n > 0:
no=n%10
if no % 2 != 0:
num+=1
n=n//10
print(num)
09 10月 2023, 02:39
09 10月 2023, ~02:39
