GITHUB REPO | FOLLOW ME ON -> TWITTER | LINKEDIN

Crush Compatibility Calculator — A Python Project for Fun

Are you interested in your compatibility with your crush? Do you want to know if you’re a great match or a disaster waiting to happen? Look no further! In this post, we’ll use Python to develop a Crush Compatibility Calculator.

Al-Junaed Islam

--

Photo by Kelly Sikkema on Unsplash

To count the number of instances of certain characters in the names, we’ll use Python’s count() function. This approach is crucial since it allows us to determine the name compatibility score.

Step-by-Step Explanation of Code

The first thing we need to do is set up our Python Crush Compatibility Calculator. Open up your preferred code editor, create a new file, and save it with a descriptive name such as “crush_calculator.py.

First, we welcome the user to the Crush Compatibility Calculator. Then, we ask for the names of the users and convert them to lowercase using lower() function. We then combine the names using a space in between.

print("Welcome to the Crush Compatibility Calculator!\n")
name1 = input("What is your name? \n->").lower()
name2 = input("What is their name? \n->").lower()

combined_name = name1 + " "+ name2

Next, we use the count() function to count the number of instances of the characters ‘t’, ‘r’, ‘u’, and ‘e’ in the combined name. Then we repeat the process for the letters ‘l’, ‘o’, ‘v’, and ‘e’. We add the two resultant values to create the compatibility score.

first_digit = combined_name.count('t') + combined_name.count('r') + combined_name.count('u') + combined_name.count('e')

second_digit = combined_name.count('l') + combined_name.count('o') + combined_name.count('v') + combined_name.count('e')

score = int(f"{first_digit}{second_digit}")

Finally, we apply a series of if/elif/else statements to compute the compatibility score and output a message to the user.

if score < 10 or score > 90:
print(f"Your score is {score}, you go together like coke and mentos.")

elif score > 40 and score < 50:
print(f"Your score is {score}, there's a little risk.")

else:
print(f"Your score is {score}, you guys will be alright together.")

Here is the full code.

crush_calculator.py

Sample Output

When the user enters their name and their crush’s name, the program will calculate the compatibility score and print out an appropriate message.

Sample Output

Ultimately, the Crush Compatibility Calculator is a fun project that calculates the compatibility score between two individuals using the Python computer language. It uses the input() function to receive user input and the count() function to compute the score. The application uses conditional statements to produce an appropriate message based on the compatibility score.

--

--