Python Forum
Love Calculator - If and Else - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Love Calculator - If and Else (/thread-3199.html)



Love Calculator - If and Else - AlwaysNew - May-04-2017

I am making a love calculator using python. I am going to use a points based system to calculate the 'Love Percentage' So I have a list of criteria;
Both first names have the same character length.[+20]
Both first names start with a vowel.[+10]
Both first names start with a consonant [+5]
Both names have the same number of vowels [+12]
Both names have the same number of consonants [+12]

I dont need answers to all of them all I need is help to work out first names that start with vowels and then I was thinking of putting the consonants in a else and vowels in a if? However my code keeps saying that the string has vowels when it does not? 
here is my code so far...

POINTS = 0
CON = 0
VOL = 0
print ("Welcome to the love calculator")
Love1 = input("Please enter the first persons name\n")
Love2 = input("Please enter the second persons name\n")

L1 = (len(Love1))
L2 = (len(Love2))

S1 = (Love1[:1])
S2 = (Love2[:1])

if L1 == L2:
    POINTS = POINTS + 20

if S1 == "a" or "e" or "i" or "o" or "u":
    POINTS = POINTS + 5
else:
    POINTS = POINTS + 2.5
if S2 == "a" or "e" or "i" or "o" or "u":
    POINTS = POINTS + 5
else:
    POINTS = POINTS + 2.5

print (POINTS)



RE: Love Calculator - If and Else - buran - May-04-2017

see http://python-forum.io/Thread-Multiple-expressions-with-or-keyword


RE: Love Calculator - If and Else - AlwaysNew - May-04-2017

Oh thank you, I literally spent two hours of my lesson today trying to work it out and i only needed brackets :)


RE: Love Calculator - If and Else - Duilonn - Apr-08-2025

You're really close! The issue is with how the if condition is written for checking vowels. In Python, this line:

if S1 == "a" or "e" or "i" or "o" or "u":
does not do what you expect. It actually always evaluates to True, because "e" (and so on) are non-empty strings, which are always truthy in Python.

✅ Correct way to check if a character is a vowel:
You should use the in keyword to check if the first character is in the string of vowels:

if S1.lower() in "aeiou":
    POINTS += 5
else:
    POINTS += 2.5

if S2.lower() in "aeiou":
    POINTS += 5
else:
    POINTS += 2.5
This checks if the first letter (in lowercase) is one of the vowels.


RE: Love Calculator - If and Else - Larz60+ - Apr-08-2025

use instead:
if S1 in "aAeEiIoOuU':
    print("S1 is a vowel")