{"id":100438,"date":"2025-01-17T08:30:05","date_gmt":"2025-01-17T07:30:05","guid":{"rendered":"https:\/\/eiposgrados.com\/?p=100438"},"modified":"2025-01-09T16:50:51","modified_gmt":"2025-01-09T15:50:51","slug":"python-chair-game","status":"publish","type":"post","link":"https:\/\/eiposgrados.com\/eng\/python-blog\/python-chair-game\/","title":{"rendered":"The musical chair game with Python"},"content":{"rendered":"<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-ad2f72ca wp-block-group-is-layout-flex\">\n<h2 class=\"wp-block-heading\"><strong>\u00a0The Python algorithm<\/strong><\/h2>\n<\/div>\n\n\n\n<p>We&#039;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:&nbsp;<\/p>\n\n\n\n<p>Who do I sit next to?&nbsp;<\/p>\n\n\n\n<p>Well don&#039;t worry, because since <a href=\"https:\/\/eip%20international%20business%20school\/\" target=\"_blank\" rel=\"noreferrer noopener\">EIP International Business School<\/a> We&#039;ll give you a hand with that dilemma.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Here&#039;s a Python algorithm that will help you choose who to sit next to.&nbsp;&nbsp;<\/p>\n\n\n\n<p>This algorithm takes into account various factors, such as your relationship with people, their interests, and whether they are good conversationalists.&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>We hope this helps. If so, please leave a comment to tell us about your experience.&nbsp;<\/p>\n\n\n\n<p>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.&nbsp;<\/p>\n\n\n\n<p># We define a class to represent each family member&nbsp;<\/p>\n\n\n\n<p>Family class:&nbsp;<\/p>\n\n\n\n<p>def init(self, name, relationship, interests, good_talker):&nbsp;<\/p>\n\n\n\n<p>self.name = name&nbsp;<\/p>\n\n\n\n<p>self.relation = relation&nbsp;<\/p>\n\n\n\n<p>self.interests = interests&nbsp;<\/p>\n\n\n\n<p>self.good_talker = good_talker&nbsp;<\/p>\n\n\n\n<p># We create a list of relatives&nbsp;<\/p>\n\n\n\n<p>relatives = [&nbsp;<\/p>\n\n\n\n<p>Familiar(\u201cUncle John\u201d, \u201cuncle\u201d, [\u201cfootball\u201d, \u201ctravel\u201d], True),&nbsp;<\/p>\n\n\n\n<p>Familiar(\u201cCousin Isabel\u201d, \u201ccousin\u201d, [\u201cart\u201d, \u201cmusic\u201d], True),&nbsp;<\/p>\n\n\n\n<p>Familiar(\u201cGrandma Maria\u201d, \u201cgrandma\u201d, [\u201ckitchen\u201d, \u201cgardening\u201d], True),&nbsp;<\/p>\n\n\n\n<p>Familiar(\u201cBrother Carlos\u201d, \u201cbrother\u201d, [\u201cvideo games\u201d, \u201cmovies\u201d], False),&nbsp;<\/p>\n\n\n\n<p>Familiar(\u201cAunt Mari \u00c1ngeles\u201d, \u201caunt\u201d, [\u201creading\u201d, \u201cwalks\u201d], True),&nbsp;<\/p>\n\n\n\n<p>]&nbsp;<\/p>\n\n\n\n<p># Function to evaluate relatives&nbsp;<\/p>\n\n\n\n<p>def choose_side(relatives):&nbsp;<\/p>\n\n\n\n<p>best_option = None&nbsp;<\/p>\n\n\n\n<p>best_score = 0&nbsp;<\/p>\n\n\n\n<p>for familiar in relatives:&nbsp;<\/p>\n\n\n\n<p>score = 0&nbsp;<\/p>\n\n\n\n<p># We increase the score according to the relationship&nbsp;<\/p>\n\n\n\n<p>if familiar.relation in [\u201cgrandmother\u201d, \u201cuncle\u201d, \u201caunt\u201d]:&nbsp;<\/p>\n\n\n\n<p>score += 2&nbsp;<\/p>\n\n\n\n<p>elif relative.relation == \u201cbrother\u201d or relative.relation == \u201ccousin\u201d:&nbsp;<\/p>\n\n\n\n<p>score += 1&nbsp;<\/p>\n\n\n\n<p># We increase the score if they are good conversationalists&nbsp;<\/p>\n\n\n\n<p>if familiar.good_talker:&nbsp;<\/p>\n\n\n\n<p>score += 2&nbsp;<\/p>\n\n\n\n<p># We increase the score if they share interests&nbsp;<\/p>\n\n\n\n<p>if \u201ccooking\u201d in familiar.interests or \u201cvideo games\u201d in familiar.interests:&nbsp;<\/p>\n\n\n\n<p>score += 1&nbsp;<\/p>\n\n\n\n<p># We check if this option is better than the previous one&nbsp;<\/p>\n\n\n\n<p>if score &gt; best_score:&nbsp;<\/p>\n\n\n\n<p>best_score = score&nbsp;<\/p>\n\n\n\n<p>best_option = family&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"439\" src=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-1024x439.jpg\" alt=\"Python\" class=\"wp-image-100474\" title=\"\" srcset=\"https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-1024x439.jpg 1024w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-300x129.jpg 300w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-768x329.jpg 768w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-123x53.jpg 123w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-1536x658.jpg 1536w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-2048x878.jpg 2048w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-18x8.jpg 18w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-500x214.jpg 500w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-800x343.jpg 800w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-1280x549.jpg 1280w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-1920x823.jpg 1920w, https:\/\/eiposgrados.com\/wp-content\/uploads\/2025\/01\/hands-coding-laptop-with-neon-pink-green-glow-evening-outdoor-setting-200x86.jpg 200w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If you want to learn how to create your own algorithms and develop your own applications, do not hesitate and ask for information at <a href=\"https:\/\/eiposgrados.com\/eng\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/eiposgrados.com\/\" rel=\"noreferrer noopener\">EIP International Business School<\/a>.\u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>\u00a0The Python algorithm We have just spent the Christmas season, full of social events, meals, dinners with friends and family, some of which are \u2026 <a title=\"The musical chair game with Python\" class=\"read-more\" href=\"https:\/\/eiposgrados.com\/eng\/python-blog\/python-chair-game\/\" aria-label=\"Read more about Python&#039;s musical chairs game\">Read more<\/a><\/p>","protected":false},"author":4227,"featured_media":100477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[407],"tags":[1528],"class_list":["post-100438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-python","tag-algoritmo"],"acf":[],"_links":{"self":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/100438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/users\/4227"}],"replies":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/comments?post=100438"}],"version-history":[{"count":0,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/posts\/100438\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media\/100477"}],"wp:attachment":[{"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/media?parent=100438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/categories?post=100438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiposgrados.com\/eng\/wp-json\/wp\/v2\/tags?post=100438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}