Advanced love calculator that generates a result based on the similarities between the two namesIs this code for a calculator efficient?Converting the first and last name to pig latinAutocomplete Trie OptimizationUltimate FizzBuzzGenerating frequency tables based on CSV datasetDataset and frequency list generation by looping over filesScrabble Tile CounterImproved version of “Let's read a random Goodreads book…”Markov country name generatorBasic calculator that calculates result based on operands using a class

What typically incentivizes a professor to change jobs to a lower ranking university?

Today is the Center

I'm flying to France today and my passport expires in less than 2 months

Roll the carpet

Why are electrically insulating heatsinks so rare? Is it just cost?

Perform and show arithmetic with LuaLaTeX

Theorems that impeded progress

How much of data wrangling is a data scientist's job?

Is it possible to do 50 km distance without any previous training?

How to format long polynomial?

What would happen to a modern skyscraper if it rains micro blackholes?

Java Casting: Java 11 throws LambdaConversionException while 1.8 does not

How can bays and straits be determined in a procedurally generated map?

Is it legal for company to use my work email to pretend I still work there?

How do I deal with an unproductive colleague in a small company?

Do infinite dimensional systems make sense?

Codimension of non-flat locus

Watching something be written to a file live with tail

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

What is a clear way to write a bar that has an extra beat?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

dbcc cleantable batch size explanation

if condition in the past



Advanced love calculator that generates a result based on the similarities between the two names


Is this code for a calculator efficient?Converting the first and last name to pig latinAutocomplete Trie OptimizationUltimate FizzBuzzGenerating frequency tables based on CSV datasetDataset and frequency list generation by looping over filesScrabble Tile CounterImproved version of “Let's read a random Goodreads book…”Markov country name generatorBasic calculator that calculates result based on operands using a class






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0












$begingroup$


My love calculator gives a result from 0 to 100% based on these factors:



  1. If the first letters of the names are the same.

  2. If the number of vowels is the same.

  3. If the length of the name is the same.

  4. If the number of consonants is the same.

Also, there is an extra boost of 10-50%, so the result is also partially as a result of luck.
Can the coding below be simplified or improved to function more smoothly?:



name1 = input("Please type Name 1.n")
name2 = input("Please type Name 2.n")

total_vowel1 =0
for i in ['a','e','i','o','u']:
total_vowel1 += name1.count(i)
total_vowel2 =0
for i in ['a','e','i','o','u']:
total_vowel2 += name2.count(i)

love = 0
if(total_vowel1 == total_vowel2):
import random
love +=random.randint(10,30)

consonants1 = 0
consonants2 = 0
CONSONANTS = 'bcdfghjklmnprstvwxyz'
consonants1 = len([letter for letter in name1 if letter.lower() in
CONSONANTS])
consonants2 = len([letter for letter in name2 if letter.lower() in
CONSONANTS])

if(consonants1 == consonants2):
import random
love +=random.randint(20,40)

line1 = name1
line2 = name2
split1 = line1.split()
split2 = line2.split()
fl1 = [word[0] for word in split1]
fl2 = [word[0] for word in split2]

if (fl1 == fl2):
import random
love +=random.randint(10,30)

if (len(name1) == len(name2)):
import random
love+=random.randint(1,10)

import random
love +=random.randint(10,50)
if (love>100):
love = 100

print("Calculating...")
import time
import random
time.sleep(random.randint(1,3))

print("",name1,"and",name2,"have a",love,"% relationship.")
if ((love>90) or (love == 90)):
print("They have an unbreakable relationship that will last
forever.")
if ((love<89) or (love == 89)) and ((love>70) or (love == 70)):
print("They have a strong relationship that will most likely
lead to a marriage.")
if ((love<69) or (love == 69)) and ((love>50) or (love == 50)):
print("They have a good relationship that can lead to a
honeymoon to Paris.")
if ((love<49) or (love == 49)):
print("They have a weak relationship that could have been a
'match made in heaven'.")









share|improve this question









New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Feels like a beginner python program. Please edit if that is not the case here.
    $endgroup$
    – hjpotter92
    31 mins ago










  • $begingroup$
    Also, please mention the python version you're using. python-3 or python-2?
    $endgroup$
    – hjpotter92
    30 mins ago

















0












$begingroup$


My love calculator gives a result from 0 to 100% based on these factors:



  1. If the first letters of the names are the same.

  2. If the number of vowels is the same.

  3. If the length of the name is the same.

  4. If the number of consonants is the same.

Also, there is an extra boost of 10-50%, so the result is also partially as a result of luck.
Can the coding below be simplified or improved to function more smoothly?:



name1 = input("Please type Name 1.n")
name2 = input("Please type Name 2.n")

total_vowel1 =0
for i in ['a','e','i','o','u']:
total_vowel1 += name1.count(i)
total_vowel2 =0
for i in ['a','e','i','o','u']:
total_vowel2 += name2.count(i)

love = 0
if(total_vowel1 == total_vowel2):
import random
love +=random.randint(10,30)

consonants1 = 0
consonants2 = 0
CONSONANTS = 'bcdfghjklmnprstvwxyz'
consonants1 = len([letter for letter in name1 if letter.lower() in
CONSONANTS])
consonants2 = len([letter for letter in name2 if letter.lower() in
CONSONANTS])

if(consonants1 == consonants2):
import random
love +=random.randint(20,40)

line1 = name1
line2 = name2
split1 = line1.split()
split2 = line2.split()
fl1 = [word[0] for word in split1]
fl2 = [word[0] for word in split2]

if (fl1 == fl2):
import random
love +=random.randint(10,30)

if (len(name1) == len(name2)):
import random
love+=random.randint(1,10)

import random
love +=random.randint(10,50)
if (love>100):
love = 100

print("Calculating...")
import time
import random
time.sleep(random.randint(1,3))

print("",name1,"and",name2,"have a",love,"% relationship.")
if ((love>90) or (love == 90)):
print("They have an unbreakable relationship that will last
forever.")
if ((love<89) or (love == 89)) and ((love>70) or (love == 70)):
print("They have a strong relationship that will most likely
lead to a marriage.")
if ((love<69) or (love == 69)) and ((love>50) or (love == 50)):
print("They have a good relationship that can lead to a
honeymoon to Paris.")
if ((love<49) or (love == 49)):
print("They have a weak relationship that could have been a
'match made in heaven'.")









share|improve this question









New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$











  • $begingroup$
    Feels like a beginner python program. Please edit if that is not the case here.
    $endgroup$
    – hjpotter92
    31 mins ago










  • $begingroup$
    Also, please mention the python version you're using. python-3 or python-2?
    $endgroup$
    – hjpotter92
    30 mins ago













0












0








0





$begingroup$


My love calculator gives a result from 0 to 100% based on these factors:



  1. If the first letters of the names are the same.

  2. If the number of vowels is the same.

  3. If the length of the name is the same.

  4. If the number of consonants is the same.

Also, there is an extra boost of 10-50%, so the result is also partially as a result of luck.
Can the coding below be simplified or improved to function more smoothly?:



name1 = input("Please type Name 1.n")
name2 = input("Please type Name 2.n")

total_vowel1 =0
for i in ['a','e','i','o','u']:
total_vowel1 += name1.count(i)
total_vowel2 =0
for i in ['a','e','i','o','u']:
total_vowel2 += name2.count(i)

love = 0
if(total_vowel1 == total_vowel2):
import random
love +=random.randint(10,30)

consonants1 = 0
consonants2 = 0
CONSONANTS = 'bcdfghjklmnprstvwxyz'
consonants1 = len([letter for letter in name1 if letter.lower() in
CONSONANTS])
consonants2 = len([letter for letter in name2 if letter.lower() in
CONSONANTS])

if(consonants1 == consonants2):
import random
love +=random.randint(20,40)

line1 = name1
line2 = name2
split1 = line1.split()
split2 = line2.split()
fl1 = [word[0] for word in split1]
fl2 = [word[0] for word in split2]

if (fl1 == fl2):
import random
love +=random.randint(10,30)

if (len(name1) == len(name2)):
import random
love+=random.randint(1,10)

import random
love +=random.randint(10,50)
if (love>100):
love = 100

print("Calculating...")
import time
import random
time.sleep(random.randint(1,3))

print("",name1,"and",name2,"have a",love,"% relationship.")
if ((love>90) or (love == 90)):
print("They have an unbreakable relationship that will last
forever.")
if ((love<89) or (love == 89)) and ((love>70) or (love == 70)):
print("They have a strong relationship that will most likely
lead to a marriage.")
if ((love<69) or (love == 69)) and ((love>50) or (love == 50)):
print("They have a good relationship that can lead to a
honeymoon to Paris.")
if ((love<49) or (love == 49)):
print("They have a weak relationship that could have been a
'match made in heaven'.")









share|improve this question









New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




My love calculator gives a result from 0 to 100% based on these factors:



  1. If the first letters of the names are the same.

  2. If the number of vowels is the same.

  3. If the length of the name is the same.

  4. If the number of consonants is the same.

Also, there is an extra boost of 10-50%, so the result is also partially as a result of luck.
Can the coding below be simplified or improved to function more smoothly?:



name1 = input("Please type Name 1.n")
name2 = input("Please type Name 2.n")

total_vowel1 =0
for i in ['a','e','i','o','u']:
total_vowel1 += name1.count(i)
total_vowel2 =0
for i in ['a','e','i','o','u']:
total_vowel2 += name2.count(i)

love = 0
if(total_vowel1 == total_vowel2):
import random
love +=random.randint(10,30)

consonants1 = 0
consonants2 = 0
CONSONANTS = 'bcdfghjklmnprstvwxyz'
consonants1 = len([letter for letter in name1 if letter.lower() in
CONSONANTS])
consonants2 = len([letter for letter in name2 if letter.lower() in
CONSONANTS])

if(consonants1 == consonants2):
import random
love +=random.randint(20,40)

line1 = name1
line2 = name2
split1 = line1.split()
split2 = line2.split()
fl1 = [word[0] for word in split1]
fl2 = [word[0] for word in split2]

if (fl1 == fl2):
import random
love +=random.randint(10,30)

if (len(name1) == len(name2)):
import random
love+=random.randint(1,10)

import random
love +=random.randint(10,50)
if (love>100):
love = 100

print("Calculating...")
import time
import random
time.sleep(random.randint(1,3))

print("",name1,"and",name2,"have a",love,"% relationship.")
if ((love>90) or (love == 90)):
print("They have an unbreakable relationship that will last
forever.")
if ((love<89) or (love == 89)) and ((love>70) or (love == 70)):
print("They have a strong relationship that will most likely
lead to a marriage.")
if ((love<69) or (love == 69)) and ((love>50) or (love == 50)):
print("They have a good relationship that can lead to a
honeymoon to Paris.")
if ((love<49) or (love == 49)):
print("They have a weak relationship that could have been a
'match made in heaven'.")






python beginner strings random






share|improve this question









New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 min ago









200_success

131k17157422




131k17157422






New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 51 mins ago









MustafaMustafa

11




11




New contributor




Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Mustafa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • $begingroup$
    Feels like a beginner python program. Please edit if that is not the case here.
    $endgroup$
    – hjpotter92
    31 mins ago










  • $begingroup$
    Also, please mention the python version you're using. python-3 or python-2?
    $endgroup$
    – hjpotter92
    30 mins ago
















  • $begingroup$
    Feels like a beginner python program. Please edit if that is not the case here.
    $endgroup$
    – hjpotter92
    31 mins ago










  • $begingroup$
    Also, please mention the python version you're using. python-3 or python-2?
    $endgroup$
    – hjpotter92
    30 mins ago















$begingroup$
Feels like a beginner python program. Please edit if that is not the case here.
$endgroup$
– hjpotter92
31 mins ago




$begingroup$
Feels like a beginner python program. Please edit if that is not the case here.
$endgroup$
– hjpotter92
31 mins ago












$begingroup$
Also, please mention the python version you're using. python-3 or python-2?
$endgroup$
– hjpotter92
30 mins ago




$begingroup$
Also, please mention the python version you're using. python-3 or python-2?
$endgroup$
– hjpotter92
30 mins ago










1 Answer
1






active

oldest

votes


















0












$begingroup$

First, your definition of consonants can be simplified a bit using set operations:



from string import ascii_lowercase

# Storing vowels in a set instead of a list
vowels = 'a', 'e', 'i', 'o', 'u'

# Read as "Take the set of lowercase letters, and remove the vowels"
consonants = set(ascii_lowercase) ^ vowels



The vowel counting code below that is repetitious. You have the same counting loop twice. This is a good place to make use of a function:



def count_vowels(name):
count = 0
for i in vowels:
count += name.count(i)

return count

total_vowel1 = count_vowels(name1)
total_vowel2 = count_vowels(name2)



Instead of importing random a few times throughout the script, just import it at the top once. Unless you have a good reason to hold off on importing something until you really need it, just import any modules right at the top for clarity.




Your spacing is kind of a mess. At different points you have:



  • total_vowel1 =0

  • consonants1 = 0

  • love +=random.randint(10,50)

  • ((love<49) or (love == 49))

  • love +=random.randint(10,30)

  • love+=random.randint(1,10)

See the problem? You're either being wildly inconsistent in your spacing, or you aren't caring to make sure your code readable and nice looking. Pick a spacing style and stick to it. I'd recommend putting spaces around infix operators (love < 49 or love == 49).




You're using two different counting and naming methods for vowels and consonants: a full loop, and a comprehension:



total_vowel1 =0
for i in ['a','e','i','o','u']:
total_vowel1 += name1.count(i)

. . .

consonants1 = len([letter for letter in name1 if letter.lower() in consonants])


Again, try to be consistent. You or someone else may need to read your code later, and consistency greatly helps readability.




((love>90) or (love == 90)) is needlessly complicated. Just write love >= 90.




In that same area, you have a bunch of ifs. They're all exclusive of each other though, so really, all the ifs after the first should be elifs.




if love <= 89 and love >= 70 (which I fixed up) could be simply written as 70 <= love <= 89. Python, unlike most languages, allows for comparison chaining.




The last case can just be an else. By elimination, if the other cases weren't picked, the last one must be.





After taking all that into consideration and fixing some more spacing, I ended up with:



from string import ascii_lowercase
import random
import time

name1 = input("Please type Name 1.n")
name2 = input("Please type Name 2.n")

vowels = 'a', 'e', 'i', 'o', 'u'
consonants = set(ascii_lowercase) ^ vowels

def count_vowels(name):
count = 0
for i in vowels:
count += name2.count(i)

return count

total_vowel1 = count_vowels(name1)
total_vowel2 = count_vowels(name2)

love = 0
if(total_vowel1 == total_vowel2):
love += random.randint(10, 30)

consonants1 = len([letter for letter in name1 if letter.lower() in consonants])
consonants2 = len([letter for letter in name2 if letter.lower() in consonants])

if(consonants1 == consonants2):
love += random.randint(20, 40)

line1 = name1
line2 = name2
split1 = line1.split()
split2 = line2.split()
fl1 = [word[0] for word in split1]
fl2 = [word[0] for word in split2]

if (fl1 == fl2):
love += random.randint(10,30)

if (len(name1) == len(name2)):
love += random.randint(1,10)

love += random.randint(10,50)

if (love > 100):
love = 100

print("Calculating...")

print(name1, "and", name2, "have a", love, "% relationship.")

if love >= 90:
print("They have an unbreakable relationship that will last forever.")

elif 70 <= love <= 89:
print("They have a strong relationship that will most likely lead to a marriage.")

elif 50 <= love <= 69:
print("They have a good relationship that can lead to a honeymoon to Paris.")

else:
print("They have a weak relationship that could have been a 'match made in heaven'.")





share|improve this answer









$endgroup$













    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Mustafa is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216946%2fadvanced-love-calculator-that-generates-a-result-based-on-the-similarities-betwe%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0












    $begingroup$

    First, your definition of consonants can be simplified a bit using set operations:



    from string import ascii_lowercase

    # Storing vowels in a set instead of a list
    vowels = 'a', 'e', 'i', 'o', 'u'

    # Read as "Take the set of lowercase letters, and remove the vowels"
    consonants = set(ascii_lowercase) ^ vowels



    The vowel counting code below that is repetitious. You have the same counting loop twice. This is a good place to make use of a function:



    def count_vowels(name):
    count = 0
    for i in vowels:
    count += name.count(i)

    return count

    total_vowel1 = count_vowels(name1)
    total_vowel2 = count_vowels(name2)



    Instead of importing random a few times throughout the script, just import it at the top once. Unless you have a good reason to hold off on importing something until you really need it, just import any modules right at the top for clarity.




    Your spacing is kind of a mess. At different points you have:



    • total_vowel1 =0

    • consonants1 = 0

    • love +=random.randint(10,50)

    • ((love<49) or (love == 49))

    • love +=random.randint(10,30)

    • love+=random.randint(1,10)

    See the problem? You're either being wildly inconsistent in your spacing, or you aren't caring to make sure your code readable and nice looking. Pick a spacing style and stick to it. I'd recommend putting spaces around infix operators (love < 49 or love == 49).




    You're using two different counting and naming methods for vowels and consonants: a full loop, and a comprehension:



    total_vowel1 =0
    for i in ['a','e','i','o','u']:
    total_vowel1 += name1.count(i)

    . . .

    consonants1 = len([letter for letter in name1 if letter.lower() in consonants])


    Again, try to be consistent. You or someone else may need to read your code later, and consistency greatly helps readability.




    ((love>90) or (love == 90)) is needlessly complicated. Just write love >= 90.




    In that same area, you have a bunch of ifs. They're all exclusive of each other though, so really, all the ifs after the first should be elifs.




    if love <= 89 and love >= 70 (which I fixed up) could be simply written as 70 <= love <= 89. Python, unlike most languages, allows for comparison chaining.




    The last case can just be an else. By elimination, if the other cases weren't picked, the last one must be.





    After taking all that into consideration and fixing some more spacing, I ended up with:



    from string import ascii_lowercase
    import random
    import time

    name1 = input("Please type Name 1.n")
    name2 = input("Please type Name 2.n")

    vowels = 'a', 'e', 'i', 'o', 'u'
    consonants = set(ascii_lowercase) ^ vowels

    def count_vowels(name):
    count = 0
    for i in vowels:
    count += name2.count(i)

    return count

    total_vowel1 = count_vowels(name1)
    total_vowel2 = count_vowels(name2)

    love = 0
    if(total_vowel1 == total_vowel2):
    love += random.randint(10, 30)

    consonants1 = len([letter for letter in name1 if letter.lower() in consonants])
    consonants2 = len([letter for letter in name2 if letter.lower() in consonants])

    if(consonants1 == consonants2):
    love += random.randint(20, 40)

    line1 = name1
    line2 = name2
    split1 = line1.split()
    split2 = line2.split()
    fl1 = [word[0] for word in split1]
    fl2 = [word[0] for word in split2]

    if (fl1 == fl2):
    love += random.randint(10,30)

    if (len(name1) == len(name2)):
    love += random.randint(1,10)

    love += random.randint(10,50)

    if (love > 100):
    love = 100

    print("Calculating...")

    print(name1, "and", name2, "have a", love, "% relationship.")

    if love >= 90:
    print("They have an unbreakable relationship that will last forever.")

    elif 70 <= love <= 89:
    print("They have a strong relationship that will most likely lead to a marriage.")

    elif 50 <= love <= 69:
    print("They have a good relationship that can lead to a honeymoon to Paris.")

    else:
    print("They have a weak relationship that could have been a 'match made in heaven'.")





    share|improve this answer









    $endgroup$

















      0












      $begingroup$

      First, your definition of consonants can be simplified a bit using set operations:



      from string import ascii_lowercase

      # Storing vowels in a set instead of a list
      vowels = 'a', 'e', 'i', 'o', 'u'

      # Read as "Take the set of lowercase letters, and remove the vowels"
      consonants = set(ascii_lowercase) ^ vowels



      The vowel counting code below that is repetitious. You have the same counting loop twice. This is a good place to make use of a function:



      def count_vowels(name):
      count = 0
      for i in vowels:
      count += name.count(i)

      return count

      total_vowel1 = count_vowels(name1)
      total_vowel2 = count_vowels(name2)



      Instead of importing random a few times throughout the script, just import it at the top once. Unless you have a good reason to hold off on importing something until you really need it, just import any modules right at the top for clarity.




      Your spacing is kind of a mess. At different points you have:



      • total_vowel1 =0

      • consonants1 = 0

      • love +=random.randint(10,50)

      • ((love<49) or (love == 49))

      • love +=random.randint(10,30)

      • love+=random.randint(1,10)

      See the problem? You're either being wildly inconsistent in your spacing, or you aren't caring to make sure your code readable and nice looking. Pick a spacing style and stick to it. I'd recommend putting spaces around infix operators (love < 49 or love == 49).




      You're using two different counting and naming methods for vowels and consonants: a full loop, and a comprehension:



      total_vowel1 =0
      for i in ['a','e','i','o','u']:
      total_vowel1 += name1.count(i)

      . . .

      consonants1 = len([letter for letter in name1 if letter.lower() in consonants])


      Again, try to be consistent. You or someone else may need to read your code later, and consistency greatly helps readability.




      ((love>90) or (love == 90)) is needlessly complicated. Just write love >= 90.




      In that same area, you have a bunch of ifs. They're all exclusive of each other though, so really, all the ifs after the first should be elifs.




      if love <= 89 and love >= 70 (which I fixed up) could be simply written as 70 <= love <= 89. Python, unlike most languages, allows for comparison chaining.




      The last case can just be an else. By elimination, if the other cases weren't picked, the last one must be.





      After taking all that into consideration and fixing some more spacing, I ended up with:



      from string import ascii_lowercase
      import random
      import time

      name1 = input("Please type Name 1.n")
      name2 = input("Please type Name 2.n")

      vowels = 'a', 'e', 'i', 'o', 'u'
      consonants = set(ascii_lowercase) ^ vowels

      def count_vowels(name):
      count = 0
      for i in vowels:
      count += name2.count(i)

      return count

      total_vowel1 = count_vowels(name1)
      total_vowel2 = count_vowels(name2)

      love = 0
      if(total_vowel1 == total_vowel2):
      love += random.randint(10, 30)

      consonants1 = len([letter for letter in name1 if letter.lower() in consonants])
      consonants2 = len([letter for letter in name2 if letter.lower() in consonants])

      if(consonants1 == consonants2):
      love += random.randint(20, 40)

      line1 = name1
      line2 = name2
      split1 = line1.split()
      split2 = line2.split()
      fl1 = [word[0] for word in split1]
      fl2 = [word[0] for word in split2]

      if (fl1 == fl2):
      love += random.randint(10,30)

      if (len(name1) == len(name2)):
      love += random.randint(1,10)

      love += random.randint(10,50)

      if (love > 100):
      love = 100

      print("Calculating...")

      print(name1, "and", name2, "have a", love, "% relationship.")

      if love >= 90:
      print("They have an unbreakable relationship that will last forever.")

      elif 70 <= love <= 89:
      print("They have a strong relationship that will most likely lead to a marriage.")

      elif 50 <= love <= 69:
      print("They have a good relationship that can lead to a honeymoon to Paris.")

      else:
      print("They have a weak relationship that could have been a 'match made in heaven'.")





      share|improve this answer









      $endgroup$















        0












        0








        0





        $begingroup$

        First, your definition of consonants can be simplified a bit using set operations:



        from string import ascii_lowercase

        # Storing vowels in a set instead of a list
        vowels = 'a', 'e', 'i', 'o', 'u'

        # Read as "Take the set of lowercase letters, and remove the vowels"
        consonants = set(ascii_lowercase) ^ vowels



        The vowel counting code below that is repetitious. You have the same counting loop twice. This is a good place to make use of a function:



        def count_vowels(name):
        count = 0
        for i in vowels:
        count += name.count(i)

        return count

        total_vowel1 = count_vowels(name1)
        total_vowel2 = count_vowels(name2)



        Instead of importing random a few times throughout the script, just import it at the top once. Unless you have a good reason to hold off on importing something until you really need it, just import any modules right at the top for clarity.




        Your spacing is kind of a mess. At different points you have:



        • total_vowel1 =0

        • consonants1 = 0

        • love +=random.randint(10,50)

        • ((love<49) or (love == 49))

        • love +=random.randint(10,30)

        • love+=random.randint(1,10)

        See the problem? You're either being wildly inconsistent in your spacing, or you aren't caring to make sure your code readable and nice looking. Pick a spacing style and stick to it. I'd recommend putting spaces around infix operators (love < 49 or love == 49).




        You're using two different counting and naming methods for vowels and consonants: a full loop, and a comprehension:



        total_vowel1 =0
        for i in ['a','e','i','o','u']:
        total_vowel1 += name1.count(i)

        . . .

        consonants1 = len([letter for letter in name1 if letter.lower() in consonants])


        Again, try to be consistent. You or someone else may need to read your code later, and consistency greatly helps readability.




        ((love>90) or (love == 90)) is needlessly complicated. Just write love >= 90.




        In that same area, you have a bunch of ifs. They're all exclusive of each other though, so really, all the ifs after the first should be elifs.




        if love <= 89 and love >= 70 (which I fixed up) could be simply written as 70 <= love <= 89. Python, unlike most languages, allows for comparison chaining.




        The last case can just be an else. By elimination, if the other cases weren't picked, the last one must be.





        After taking all that into consideration and fixing some more spacing, I ended up with:



        from string import ascii_lowercase
        import random
        import time

        name1 = input("Please type Name 1.n")
        name2 = input("Please type Name 2.n")

        vowels = 'a', 'e', 'i', 'o', 'u'
        consonants = set(ascii_lowercase) ^ vowels

        def count_vowels(name):
        count = 0
        for i in vowels:
        count += name2.count(i)

        return count

        total_vowel1 = count_vowels(name1)
        total_vowel2 = count_vowels(name2)

        love = 0
        if(total_vowel1 == total_vowel2):
        love += random.randint(10, 30)

        consonants1 = len([letter for letter in name1 if letter.lower() in consonants])
        consonants2 = len([letter for letter in name2 if letter.lower() in consonants])

        if(consonants1 == consonants2):
        love += random.randint(20, 40)

        line1 = name1
        line2 = name2
        split1 = line1.split()
        split2 = line2.split()
        fl1 = [word[0] for word in split1]
        fl2 = [word[0] for word in split2]

        if (fl1 == fl2):
        love += random.randint(10,30)

        if (len(name1) == len(name2)):
        love += random.randint(1,10)

        love += random.randint(10,50)

        if (love > 100):
        love = 100

        print("Calculating...")

        print(name1, "and", name2, "have a", love, "% relationship.")

        if love >= 90:
        print("They have an unbreakable relationship that will last forever.")

        elif 70 <= love <= 89:
        print("They have a strong relationship that will most likely lead to a marriage.")

        elif 50 <= love <= 69:
        print("They have a good relationship that can lead to a honeymoon to Paris.")

        else:
        print("They have a weak relationship that could have been a 'match made in heaven'.")





        share|improve this answer









        $endgroup$



        First, your definition of consonants can be simplified a bit using set operations:



        from string import ascii_lowercase

        # Storing vowels in a set instead of a list
        vowels = 'a', 'e', 'i', 'o', 'u'

        # Read as "Take the set of lowercase letters, and remove the vowels"
        consonants = set(ascii_lowercase) ^ vowels



        The vowel counting code below that is repetitious. You have the same counting loop twice. This is a good place to make use of a function:



        def count_vowels(name):
        count = 0
        for i in vowels:
        count += name.count(i)

        return count

        total_vowel1 = count_vowels(name1)
        total_vowel2 = count_vowels(name2)



        Instead of importing random a few times throughout the script, just import it at the top once. Unless you have a good reason to hold off on importing something until you really need it, just import any modules right at the top for clarity.




        Your spacing is kind of a mess. At different points you have:



        • total_vowel1 =0

        • consonants1 = 0

        • love +=random.randint(10,50)

        • ((love<49) or (love == 49))

        • love +=random.randint(10,30)

        • love+=random.randint(1,10)

        See the problem? You're either being wildly inconsistent in your spacing, or you aren't caring to make sure your code readable and nice looking. Pick a spacing style and stick to it. I'd recommend putting spaces around infix operators (love < 49 or love == 49).




        You're using two different counting and naming methods for vowels and consonants: a full loop, and a comprehension:



        total_vowel1 =0
        for i in ['a','e','i','o','u']:
        total_vowel1 += name1.count(i)

        . . .

        consonants1 = len([letter for letter in name1 if letter.lower() in consonants])


        Again, try to be consistent. You or someone else may need to read your code later, and consistency greatly helps readability.




        ((love>90) or (love == 90)) is needlessly complicated. Just write love >= 90.




        In that same area, you have a bunch of ifs. They're all exclusive of each other though, so really, all the ifs after the first should be elifs.




        if love <= 89 and love >= 70 (which I fixed up) could be simply written as 70 <= love <= 89. Python, unlike most languages, allows for comparison chaining.




        The last case can just be an else. By elimination, if the other cases weren't picked, the last one must be.





        After taking all that into consideration and fixing some more spacing, I ended up with:



        from string import ascii_lowercase
        import random
        import time

        name1 = input("Please type Name 1.n")
        name2 = input("Please type Name 2.n")

        vowels = 'a', 'e', 'i', 'o', 'u'
        consonants = set(ascii_lowercase) ^ vowels

        def count_vowels(name):
        count = 0
        for i in vowels:
        count += name2.count(i)

        return count

        total_vowel1 = count_vowels(name1)
        total_vowel2 = count_vowels(name2)

        love = 0
        if(total_vowel1 == total_vowel2):
        love += random.randint(10, 30)

        consonants1 = len([letter for letter in name1 if letter.lower() in consonants])
        consonants2 = len([letter for letter in name2 if letter.lower() in consonants])

        if(consonants1 == consonants2):
        love += random.randint(20, 40)

        line1 = name1
        line2 = name2
        split1 = line1.split()
        split2 = line2.split()
        fl1 = [word[0] for word in split1]
        fl2 = [word[0] for word in split2]

        if (fl1 == fl2):
        love += random.randint(10,30)

        if (len(name1) == len(name2)):
        love += random.randint(1,10)

        love += random.randint(10,50)

        if (love > 100):
        love = 100

        print("Calculating...")

        print(name1, "and", name2, "have a", love, "% relationship.")

        if love >= 90:
        print("They have an unbreakable relationship that will last forever.")

        elif 70 <= love <= 89:
        print("They have a strong relationship that will most likely lead to a marriage.")

        elif 50 <= love <= 69:
        print("They have a good relationship that can lead to a honeymoon to Paris.")

        else:
        print("They have a weak relationship that could have been a 'match made in heaven'.")






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 12 mins ago









        CarcigenicateCarcigenicate

        3,85011632




        3,85011632




















            Mustafa is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            Mustafa is a new contributor. Be nice, and check out our Code of Conduct.












            Mustafa is a new contributor. Be nice, and check out our Code of Conduct.











            Mustafa is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Code Review Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216946%2fadvanced-love-calculator-that-generates-a-result-based-on-the-similarities-betwe%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

            格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订