Help needed in Python

Status
Not open for further replies.

zeeshanqam

Junior Member level 3
Joined
Sep 9, 2009
Messages
30
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Location
Pakistan
Visit site
Activity points
1,462
I have an assignment and I want to run this code in Python ASAP. I dont have any idea of this language Any one here could help me out please.. I appreciate his/her efforts..

There are two files with ASCII type.

You can program by using python as follows: 1. Your program read two files in respectively. 2. Each file is composed of xyz value in float type(in real value). You can calculate the distance by using randomly choosing between two points. Sampling number depends on you. Then you can make the histogram composed of distances and frequencies. 3. Program calculate the similiarity value by using histogram comparison(we already discuss this issues). 4. Program write the similarity value in file or console.

fileA ------------------------------------
35.884 30.895 49.120 36.177 29.853 50.124 37.296 30.296 51.074 38.553 30.400 50.259 38.357 31.290 49.044 39.559 31.209 48.082 34.968 30.340 48.234 34.923 29.775 50.910 37.441 29.265 52.113 39.572 30.954 51.086 37.155 30.858 48.364 39.261 32.018 46.920 ------------------------------------
fileB ------------------------------------
35.884 30.895 49.120 36.177 29.853 50.124 37.296 30.296 51.074 37.441 29.265 52.113 39.572 30.954 51.086 37.155 30.858 48.364 39.261 32.018 46.920

thank you in advance
 
Last edited:

step 1. focus on your presentation.
step 2. learn python. try codecademy or other free tutorial sites.
step 3. code solution.
Having someone else do your schoolwork is unethical. So is doing someone else's schoolwork.
 

...Python... I dont have any idea of this language
If you already know how to program in some other language e.g. Visual Basic, C or Java, then you should find it easy to learn Python.

One interesting feature of the language is that it does not use twirly brackets to delimit code blocks. Indentation is used instead. For example, here's a snippet of code from something I'm working on now:

Code:
    ml_brains = catalog(object_provides=IBikaFolder.__identifier__, logical_title="root: Member Labs")
    if len(ml_brains) == 0:
       member_labs_folder = createObject('bika.interlab.bikafolder')
       member_labs_folder.title = "Member Labs"
       member_labs_folder.logical_title = "root: Member Labs"
       member_labs_folder.reindexObject()
       addContentToContainer(portal, member_labs_folder, checkConstraints=False)
    else:
       member_labs_folder = ml_brains[0].getObject()
    alsoProvides(member_labs_folder, IMemberLabsFolder)

Note that the first line, the last line, the if statement, and the else statement are all indented exactly the same amount. Similarly, the 5 lines immediately after the if statement are all indented the same as each other. If one of those 5 lines was indented a different amount, it would cause a syntax error. I like this language feature as it enforces reasonably neat code and saves you having to type lots of brackets.

Other than that it's a pretty normal language. It supports object orientation, but you probably don't need to go into that for a simple assignment like this. You'll probably need to use lists and/or dictionaries, though. There's a nice tutorial on that here: http://www.sthurlow.com/python/lesson06/. I see there's links there to other topics too, that should be enough to get you going.
 

This sounds like a statistics class. I wish we could have done statistics with something real like Python. Instead we used a dumb program called SPSS.

This is a good time to try writing some psudocode. Just write down the steps that you would go through to accomplish this task, and then go through each step and make it more specific by breaking down each step into smaller ones. Actually, the instructions your were given is already a high level psudocode, so the professor is trying to help you. (And you though he was being mean.)

By the time you've fleshed out the psudocode enough, each step should correspond to a simple google search. Like how to read files in python, how to generate random numbers in python, how to create loops in python, how to create arrays in python, and so forth.

His instructions with a little editing and some psudocode. (sheesh, I'm doing your work)
1. Your program read two files in respectively. Each file is composed of xyz value in float type(in real value).
read in file 1 (probably going to be a loop, but I don't know)
store in array1

read in file 2 (probably going to be a loop, but I don't know)
store in array2

2. Calculate the distance by using randomly choosing between two points. Sampling number depends on you
set sample_number to something big but not too big
loop i from 1 to sample_number
get random point from array1
get random point from array2
calculate distance between points and append value onto array3

3. Make the histogram composed of distances and frequencies
make histogram array for bins initialized to zeros
loop i with array3
figure out which bin number i goes in
increment the histogram array indexed by the bin number by 1

4. Calculate the similarity value by using histogram comparison
what in the tarnations is a similarity?

4. Print out the similarity value in file or console
one step baby, print that number

It's bad groove to code without planning unless you already have great groove, in which case it supers your groove.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…