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 is the 'F', and the final character (the ‘d’) is in myname.
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) 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