How to Create a Love Calculator using lower() and count() Functions in Python

Create a Love Calculator using lower() and count() Functions in Python

This blog will help you to learn about functions like lower, and count using that, We will be creating a love calculator (Which would be Fun !!)

Functions:

  • lower()
  • count()

lower()

This function will convert the input string into lowercase. This helps to reduce the complexity for users So that they can try in any case they want.

For example

print(“PyTHOn”.lower() )

=>python

count()

This function will print the number of times specified input occurs in a string or a variable

example:

print(“LearnandShare”.count(“a”))

=>3

Code:

print("Welcome to the Love Calculator!")

name1 = input("What is your name? \n")

name2 = input("What is their name? \n")

name=name1.lower()+name2.lower()

true_count=name.count("t")+name.count("r")+name.count("u")+name.count("e")

love_count=name.count("l")+name.count("o")+name.count("v")+name.count("e")

score=str(true_count)+str(love_count)

if int(score) < 10 or int(score) > 90:

print (f"Your score is {score}, you go together like coke and mentos.")

elif int(score) > 40 and int(score) <50:

print (f"Your score is {score}, you are alright together.")

else:

print (f"Your score is {score}.")

Try it yourself

Explanation:

Let’s see, How this Love Calculator works:

– To create a love calculator, We need to get 2 names as an input

– Find the number of times the letter “T R U E ” & “L O V E” is occurring in both the name

– Then combine these numbers to make a 2-digit number.

– Once done, Based on the score, We need to share the Love levels

  • For a Score of less than 10 or greater than 90, then we need to show as the message below

“Your score is {score}, you go together like coke and mentos.”

  • For a Score between 40 and 50, the message should be:

“Your score is {score}, you are alright together.”

  • Otherwise, We can just print the score

“Your score is {score}.”

Check here for more Python learning series posts

Good Luck with your learning. Hit like if this post is helpful

Similar Posts