Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |
 User Name: Password: Remember me

New Free Tools on Dev Shed!
We're Excited to announce that Dev Shed now has 70 free tools on the site. To learn more, click here!

 Add This Thread To: Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb
 « Previous Thread | Next Thread » Thread Tools Search this Thread Rate Thread Display Modes
 Dev Shed Forums Sponsor:
#1
April 27th, 2013, 06:38 AM
 kidoman
Contributing User

Join Date: Mar 2013
Posts: 55
Time spent in forums: 5 h 46 m 15 sec
Reputation Power: 1
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
April 27th, 2013, 10:40 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,140
Time spent in forums: 1 Month 3 Weeks 2 Days 7 h 17 m 40 sec
Reputation Power: 455
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!

#3
April 27th, 2013, 08:19 PM
 kidoman
Contributing User

Join Date: Mar 2013
Posts: 55
Time spent in forums: 5 h 46 m 15 sec
Reputation Power: 1
Quote:
 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 "", line 1, in 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
 A6 -159171 (2013) (1).pdf (197.4 KB, 24 views)

#4
April 27th, 2013, 09:21 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,140
Time spent in forums: 1 Month 3 Weeks 2 Days 7 h 17 m 40 sec
Reputation Power: 455
You must discuss your relative's demise with Professor Moretti.

#5
April 27th, 2013, 11:22 PM
 kidoman
Contributing User

Join Date: Mar 2013
Posts: 55
Time spent in forums: 5 h 46 m 15 sec
Reputation Power: 1
Quote:
 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

#6
April 28th, 2013, 02:10 AM
 kidoman
Contributing User

Join Date: Mar 2013
Posts: 55
Time spent in forums: 5 h 46 m 15 sec
Reputation Power: 1
Quote:
 Originally Posted by b49P23TIvg You must discuss your relative's demise with Professor Moretti.

Can you help me start it? please

#7
April 28th, 2013, 09:06 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,140
Time spent in forums: 1 Month 3 Weeks 2 Days 7 h 17 m 40 sec
Reputation Power: 455
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.

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Urgent help needed.

## Developer Shed Advertisers and Affiliates

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox Forum Jump Please select one User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home -------------------- Programming Languages    PHP Development        PHP FAQs and Stickies    Perl Programming        Perl FAQs and Stickies    C Programming        C Programming FAQs and Stickies    Java Help        Java FAQs    Python Programming        Python Programming FAQs    Ruby Programming        Ruby Programming FAQs    Game Development        Game Development FAQs Programming Languages - More    ASP Programming        ASP Programming FAQs    .Net Development        .Net Development FAQs    Visual Basic Programming        Visual Basic Programming FAQs    Software Design        Software Design FAQs    ColdFusion Development        ColdFusion Development FAQs    Delphi Programming        Delphi Programming FAQs    Regex Programming        Regex Programming FAQs    XML Programming        XML Programming FAQs    Other Programming Languages        Other Programming Languages FAQs Web Design    HTML Programming        HTML Programming FAQs    JavaScript Development        JavaScript Development FAQs    CSS Help        CSS Help FAQs    Flash Help        Flash Help FAQs    Photoshop Help        Photoshop Help FAQs    Web Design Help        Web Design Help FAQs    Website Critiques        Website Critiques FAQs    Search Engine Optimization        Search Engine Optimization FAQs Mobile Programming    Mobile Programming        Mobile Programming FAQs    iPhone SDK Development        iPhone SDK Development FAQs    Android Development        Android Development FAQs    BlackBerry Development        BlackBerry Development FAQs Web Site Management    Business Help        Business Help FAQs    Development Software        Development Software FAQs    Scripts        Scripts FAQs Databases    Database Management        Database Management FAQs    DB2 Development        DB2 Development FAQs    MySQL Help        MySQL Help FAQs    PostgreSQL Help        PostgreSQL Help FAQs    Firebird SQL Development        Firebird SQL Development FAQs    MS SQL Development        MS SQL Development FAQs    Oracle Development        Oracle Development FAQs    LDAP Programming        LDAP Programming FAQs System Administration    Mail Server Help        Mail Server Help FAQs    Apache Development        Apache Development FAQs    Security and Cryptography        Security and Cryptography FAQs    Antivirus Protection        Antivirus Protection FAQs    DNS        DNS FAQs    IIS        IIS FAQs    Networking Help        Networking Help FAQs    FTP Help        FTP Help FAQs Operating Systems    BSD Help        BSD Help FAQs    Linux Help        Linux Help FAQs    UNIX Help        UNIX Help FAQs    Windows Help        Windows Help FAQs    Mac Help        Mac Help FAQs Web Hosting    Web Hosting        Web Hosting FAQs    Free Web Hosting        Free Web Hosting FAQs    Web Hosting Requests        Web Hosting Requests FAQs    Web Hosting Offers        Web Hosting Offers FAQs Computer Hardware    Computer Hardware    CPUs        CPUs FAQs    Cooling        Cooling FAQs    Embedded Programming        Embedded Programming FAQs    Motherboards        Motherboards FAQs    Multimedia Hardware        Multimedia Hardware FAQs Other    Dev Shed Lounge        Dev Shed Lounge FAQs    Development Articles        Development Articles FAQs    Beginner Programming        Beginner Programming FAQs    Hire A Programmer        Hire A Programmer FAQs    Project Help Wanted        Project Help Wanted FAQs Latest News Updated Hourly    Technology News    Business News    Science News Forum Information    Forum Rules/Guidelines        Forum Rules/Guidelines FAQs    Forum Announcements        Forum Announcements FAQs    Dev Shed Gaming Center        Go to the Dev Shed Battle Arena        Go to the Dev Shed Arcade Games        Go to the Legend of the Green Dragon    Suggestions & Feedback        Suggestions & Feedback FAQs

 Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap