#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2

    Unhappy Urgent help needed.


    A Romance Compatibility Calculator – 4 marks

    There is a theory (which I've just thought up based on absolutely no evidence) that it's possible to calculate the romantic compatibility between two people using just their names.


    The process for doing this is:
    • derive a person's score by treating each letter of their name as a number and adding them all up.
    • find the remainder when dividing this number by 100 (e.g. 537 gives 37, 401 gives 1 ...)
    • find the difference between the two scores, returning the absolute value (e.g. convert -37 to 37)
    • display this value as a percentage compatibility value (based on the dubious supposition that the larger the difference in scores, the more compatible you are). The value isn’t a percentage but it looks better when displayed that way.


    Write a program to calculate the compatibility value for two names.

    • if the names are different and neither is blank, display their compatibility.

    • if the names are the same, or either is empty, display an appropriate error message informing the
    user what's wrong.

    Picking out the characters
    Method #1: You can pick out individual characters from a string using subscripts (e.g. if the string myname contains 'Fred', myname[0] is the 'F', and the final character (the ‘d’) is in myname[3].

    Method #2: this is simpler than method #1. It uses the for – in construct:
    for ch in s: # where s is any string and ch is the picked-out character
    do something with the character ch

    To find the integer value of a character use the ord() function: intValue = ord(myname[2]) OR
    intValue = ord(s)

    Once you’ve can find the value of each character, you add them up. The accumulator pattern is useful here. Important: To ensure that you don’t have any spaces before or after the name, use the strip() method:
    e.g. myname = myname.strip() as trailing spaces won’t be visible but will affect the numeric total. Remainders: You can use the % operator to find remainder of a division: e.g. 14 % 5 gives 2


    Please help, its due tomorrow and ive had to deal with a funereal of my relative so i didnt have time to look at it this week
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    Consider Lisa and Peter.

    In EBCDIC Lisa scores 39; Peter: 97. Their compatibility is therefor 58%.

    Now, in ASCII, and this being a python forum maybe we have to live with ASCII, Lisa is 93 while Peter gets 12, making them a whopping 81% compatible couple.

    Google finds 14 million "lisa peter marriage" hits, and 6.7 divorce. We need more data!

    But seriously, to find a mate you'd score yourself versus all acceptable partner names, then go a-huntin'.

    But seriously, how do we go about this in python3?

    >>> sum(bytes('Lisa','ascii'))
    393

    Ah! As I foresaw, the answer depends on the encoding.

    Code:
    >>> bytes('Lisa','ebcdic')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    LookupError: unknown encoding: ebcdic
    Yup, I did extra work for the punch card encoding. Care to verify my result?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Consider Lisa and Peter.

    In EBCDIC Lisa scores 39; Peter: 97. Their compatibility is therefor 58%.

    Now, in ASCII, and this being a python forum maybe we have to live with ASCII, Lisa is 93 while Peter gets 12, making them a whopping 81% compatible couple.

    Google finds 14 million "lisa peter marriage" hits, and 6.7 divorce. We need more data!

    But seriously, to find a mate you'd score yourself versus all acceptable partner names, then go a-huntin'.

    But seriously, how do we go about this in python3?

    >>> sum(bytes('Lisa','ascii'))
    393

    Ah! As I foresaw, the answer depends on the encoding.

    Code:
    >>> bytes('Lisa','ebcdic')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    LookupError: unknown encoding: ebcdic
    Yup, I did extra work for the punch card encoding. Care to verify my result?
    I will attach the file, can you please help me with problem 2. i have under 5 hours to do it
    I have a maths assignment to do as well
    Attached Files
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    You must discuss your relative's demise with Professor Moretti.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Originally Posted by b49P23TIvg
    You must discuss your relative's demise with Professor Moretti.
    I already talked to him and he said they can never extend the deadline for anyone for whatever reason
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    55
    Rep Power
    2
    Originally Posted by b49P23TIvg
    You must discuss your relative's demise with Professor Moretti.
    Can you help me start it? please
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    sum(bytes('Lisa','ascii'))

    This I showed, it's a great way to "by treating each letter of their name as a number and adding them all up."

    a%b

    % gives the remainder after subtracting from a an integer multiple of b. That information is supplied with the question, however, incorrectly with the bizarre "14 % 5 gives 2". Well, I can see how you may have been misled but the python website will clearly state the function and if you don't understand, try it until you're satisfied within the python interpreter.

    "find the difference between two scores"
    a-b
    - is the difference.
    But there's a BIG complication. You need to compute the sum of the ASCII values mod 100 for TWO names to get enough information for the dyadic subtraction.

    "absolute value"
    abs(x)
    abs returns the absolute value of x.

    Or you could subtract the bigger value from the smaller.

    Or you could convert the difference to a string and remove a negative sign. I prefer abs.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo