Skip to content

Instantly share code, notes, and snippets.

@mskian
Last active February 29, 2024 16:45
Show Gist options
  • Save mskian/033e3503a29764d252a60977c2138767 to your computer and use it in GitHub Desktop.
Save mskian/033e3503a29764d252a60977c2138767 to your computer and use it in GitHub Desktop.
Python Script to Calculate the FLAMES value between you and your partner
import re
import sys
import time
def validate_name(name):
name = ' '.join(name.split())
if not re.match("^[a-zA-Z ]+$", name):
print("\nInvalid input! Name should contain only alphabets and spaces.\n")
return False
return True
def remove_common_letters(name1, name2):
name1_lower = name1.lower()
name2_lower = name2.lower()
for char in name1_lower:
if char in name2_lower:
name1 = name1.replace(char, '', 1)
name2 = name2.replace(char, '', 1)
return name1, name2
def calculate_flames(name1, name2):
flames = ['Friendship', 'Love', 'Affection', 'Marriage', 'Enemy', 'Sibling']
remaining_letters = len(name1 + name2)
while len(flames) > 1:
flames_index = (remaining_letters - 1) % len(flames)
flames.pop(flames_index)
return flames[0]
def display_result(relationship):
result_mapping = {
'Friendship': ('👫', '\033[92m'),
'Love': ('❤️', '\033[91m'),
'Affection': ('😊', '\033[93m'),
'Marriage': ('💍', '\033[95m'),
'Enemy': ('👿', '\033[96m'),
'Sibling': ('👭', '\033[94m')
}
emoji, color_code = result_mapping.get(relationship, ('', '\033[0m'))
print(f"\n{color_code}{relationship} {emoji}\n\033[0m")
def main():
try:
while True:
name1 = input("Enter the first name (or 'exit' to quit): ").strip()
if name1.lower() == 'exit':
print("Goodbye!")
break
name2 = input("Enter the second name: ").strip()
if not validate_name(name1) or not validate_name(name2):
continue
name1, name2 = remove_common_letters(name1, name2)
relationship = calculate_flames(name1, name2)
spinner = ['-', '\\', '|', '/']
for i in range(1, 101, 9):
sys.stdout.write('\r')
sys.stdout.write("[%-10s] %d%% %s" % ('=' * (i//10), i, spinner[i//10 % len(spinner)]))
sys.stdout.flush()
time.sleep(0.2)
sys.stdout.write('\r')
sys.stdout.write(' ' * 20)
sys.stdout.write('\r')
sys.stdout.flush()
display_result(relationship)
except KeyboardInterrupt:
print("\nExiting...")
exit()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment