The Python algorithm
We've just passed the Christmas season, filled with social events, lunches, and dinners with friends and family. Some of these events may be more about commitment than pleasure, and during which we often ask ourselves the following question:
Who do I sit next to?
Well don't worry, because since EIP International Business School We'll give you a hand with that dilemma.
Here's a Python algorithm that will help you choose who to sit next to.
This algorithm takes into account various factors, such as your relationship with people, their interests, and whether they are good conversationalists.
We hope this helps. If so, please leave a comment to tell us about your experience.
First, we define a list of family members and some attributes that may influence your decision. Then, the algorithm will evaluate each person and suggest the best option.
# We define a class to represent each family member
Family class:
def init(self, name, relationship, interests, good_talker):
self.name = name
self.relation = relation
self.interests = interests
self.good_talker = good_talker
# We create a list of relatives
relatives = [
Familiar(“Uncle John”, “uncle”, [“football”, “travel”], True),
Familiar(“Cousin Isabel”, “cousin”, [“art”, “music”], True),
Familiar(“Grandma Maria”, “grandma”, [“kitchen”, “gardening”], True),
Familiar(“Brother Carlos”, “brother”, [“video games”, “movies”], False),
Familiar(“Aunt Mari Ángeles”, “aunt”, [“reading”, “walks”], True),
]
# Function to evaluate relatives
def choose_side(relatives):
best_option = None
best_score = 0
for familiar in relatives:
score = 0
# We increase the score according to the relationship
if familiar.relation in [“grandmother”, “uncle”, “aunt”]:
score += 2
elif relative.relation == “brother” or relative.relation == “cousin”:
score += 1
# We increase the score if they are good conversationalists
if familiar.good_talker:
score += 2
# We increase the score if they share interests
if “cooking” in familiar.interests or “video games” in familiar.interests:
score += 1
# We check if this option is better than the previous one
if score > best_score:
best_score = score
best_option = family

If you want to learn how to create your own algorithms and develop your own applications, do not hesitate and ask for information at EIP International Business School.