Share on social networks!

The musical chair game with Python

 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 

Python

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

Director of R&D, Funditec

Subscribe to our newsletter to stay up to date with all the news

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.
marter-in-python

Leave a comment

EIP International Business School informs you that the data in this form will be processed by Mainjobs Internacional Educativa y Tecnológica, SAU as the party responsible for this website. The purpose of collecting and processing personal data is to manage your subscription to the newsletter as well as to send commercial information about the services of the data controller. The legitimacy is the explicit consent of the interested party. Data will not be transferred to third parties, except under legal obligation. You may exercise your rights of access, rectification, limitation and deletion of data at compliance@grupomainjobs.com, as well as the right to lodge a complaint with the supervisory authority. You can consult additional and detailed information on Data Protection in the Privacy Policy that you will find on our website.