Flames Program in Python

python program for flames
Reading Time: 8 minutes

Introduction

The FLAMES game is a popular relationship prediction game based on the letters in two people’s names. FLAMES stands for Friends, Lovers, Affectionate, Marriage, Enemies, and Siblings. The game predicts the relationship between two individuals based on the common letters in their names.

Algorithm for the FLAMES Game:

  1. Define the function remove_matching_letters(name1, name2): a. Convert both name1 and name2 to lowercase to ensure case-insensitive matching. b. Loop through each character char in name1. c. Check if char exists in name2. d. If char is present in name2, remove the first occurrence of char from both name1 and name2. e. Continue the loop until all common letters are removed from both names. f. Return the modified name1 and name2.
  2. Define the function flames_result(name1, name2): a. Initialize a string relation with the value “FLAMES”. This string will be shortened to determine the relationship. b. Create a dictionary result_map to map the final letter of relation to the corresponding relationship type. c. Call the remove_matching_letters(name1, name2) function to get name1 and name2 with common letters removed. d. Calculate the count of remaining letters in both name1 and name2. e. If both names are identical, i.e., no remaining letters after common letters removal, return a message indicating to enter different names. f. Run a loop until relation is reduced to a single letter: – Calculate the index as (count % len(relation)) – 1. – If the index is non-negative, remove the letter at the calculated index from relation. – If the index is negative, remove the last letter from relation. g. The final value of relation will be a single letter representing the relationship type. h. Use the result_map to get the corresponding relationship and return it.
  3. In the main part of the program: a. Print a welcome message for the FLAMES game. b. Take input for name1 and name2. c. Call the flames_result(name1, name2) function to get the relationship result. d. Print the result message indicating the relationship between the two names.

Explanation:

The program implements the FLAMES game, which is a fun way to predict the relationship between two individuals based on the letters in their names. It uses two functions: remove_matching_letters and flames_result.

  1. remove_matching_letters: This function removes the common letters from both name1 and name2. It converts the names to lowercase to ensure case-insensitive matching and then iterates through name1. If a character is found in name2, it removes that character from both names using the replace
  2. flames_result: This function calculates the FLAMES result for two names. It starts with the initial relationship “FLAMES” and uses a dictionary (result_map) to map each letter of the shortened relation string to the corresponding relationship type. It calls remove_matching_letters to get the modified name1 and name2. Afterward, it calculates the count of remaining letters in both names and runs a loop until the relation is reduced to a single letter. The loop iteratively removes letters from the relation string based on the count and updates the relation. Finally, it returns the relationship type based on the final value of the relation.

In the main part of the program, the user is prompted to enter two names. The flames_result function is called with these names, and the result is displayed, indicating the predicted relationship between the two names.

Python Code :

				
					def remove_matching_letters(name1, name2):
    name1 = name1.lower()
    name2 = name2.lower()
    for char in name1:
        if char in name2:
            name1 = name1.replace(char, '', 1)
            name2 = name2.replace(char, '', 1)
    return name1, name2
def flames_result(name1, name2):
    relation = "FLAMES"
    result_map = {
        'F': "Friends",
        'L': "Lovers",
        'A': "Affectionate",
        'M': "Marriage",
        'E': "Enemies",
        'S': "Siblings"
    }
    name1, name2 = remove_matching_letters(name1, name2)
    count = len(name1) + len(name2)
    if count == 0:
        return "Names are identical. Please enter different names."
    while len(relation) > 1:
        index = (count % len(relation)) - 1
        if index >= 0:
            relation = relation[:index] + relation[index + 1:]
        else:
            relation = relation[:len(relation) - 1]
    return result_map[relation]
if __name__ == "__main__":
    print("Welcome to the FLAMES game!")
    name1 = input("Enter the first name: ")
    name2 = input("Enter the second name: ")
    result = flames_result(name1, name2)
    print(f"The relationship between {name1} and {name2} is: {result}")
				
			

Input :

				
					Welcome to the FLAMES game!
Enter the first name: john
Enter the second name: jenny
				
			

Output :

				
					The relationship between john and jenny is: Marriage
				
			

In this example, the program takes two names as input (John and Jeni) and returns the relationship prediction (Marriage) based on the FLAMES game rules. Remember, the game is for fun and entertainment purposes and has no scientific basis.