Small Project on Python (Conditional Statements)

Last updated on

Hello Guys!

Are you on the way to diving deep into Python programming?

Let’s have some code practice together.

So, the topic for today’s project will be related to Python Conditional Statements.

Let’s begin the Journey!

Project Name: Love Calculator

You will write a program to test the compatibility between two people by calculating their love score.

  • Let’s suppose there are two people, name1 and name2.
  • We will calculate how many times the letters ‘l,’ ‘o,’ ‘v,’ and ‘e’ occur in their names, as well as how many times ‘t,’ ‘r,’ ‘u,’ and ‘e’ occur.
  • Then, we’ll combine the counts for ‘love’ and ‘true’ to determine a “love score i.e. love percentage.”
  • If the love percentage is less than 10 or greater than 90 print the message: your love percentage is {love_percent} and enjoy the Coke with pizza together
  • Otherwise, if the love percentage is greater than 40 and less than 50 print the message: your love percentage is {love_percent} and hold an amazing bond
  • Else print the message: your love percentage is {love_percent}

Not cleared? Scroll down to the picture…

Problem Statement of the task love calculator needed to be done

Hold on! First, try it by yourself.

I hope you did it, however, if not, I’d be happy to help you clarify and improve your code. Get the code below👇

Code for Love Percentage

Python code for love percentage project

Output:

Want to check the code? Copy and paste the below code to Python IDE.

print("Welcome to love calculator!")
name1=input("what is your name")
name2=input("what is their name")
name=(name1 + name2 ).lower()  #making all the name letter to lower case

print("calculating the love percentage between: "+name)
count_t=name.count("t")
count_r=name.count("r")
count_u=name.count("u")
count_ee=name.count("e")
true=(count_t+count_r+count_u+count_ee)     #sum the total count for true

count_l=name.count("l")
count_o=name.count("o")
count_v=name.count("v")
count_e=name.count("e")
love=(count_l+count_o+count_v+count_e) #sum the total count for love

love_percent=int(str(true)+str(love))       #concat the true and love counts

if love_percent<10 or love_percent>90:
    print(f"your love percentage is {love_percent} and enjoy the coke with pizza together")
elif love_percent>40 and love_percent<50:
    print(f"your love percentage is {love_percent} and hold an amazing bond")
else:
 print(f"your love percentage is {love_percent}") 

Wrapping it up!

Congratulations to you for dedicating time and effort to coding!


Continuous practice and learning are key to becoming a better coder.

If you have any coding questions or need assistance with anything related to programming, feel free to ask. Cheers!😊


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *