Need Help with Programming Science Project
Dave Angel
davea at davea.name
Sat Jan 25 01:38:42 EST 2014
kvxdelta at gmail.com Wrote in message:
> Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways:
.........
>
>
> LPW_Comparisons = [avgLPW_DJ_EXAMPLE, avgLPW_SUZC_EXAMPLE, avgLPW_SUZC_EXAMPLE]
> avgLPW_Match = min(LPW_Comparisons)
>
> if avgLPW_Match == avgLPW_DJ_EXAMPLE:
> DJMachalePossibility = (DJMachalePossibility+1)
>
> if avgLPW_Match == avgLPW_SUZC_EXAMPLE:
> SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1)
>
> if avgLPW_Match == avgLPW_RICH_EXAMPLE:
> RichardPeckPossibility = (RichardPeckPossibility+1)
>
> AUTHOR_SCOREBOARD = [DJMachalePossibility, SuzanneCollinsPossibility, RichardPeckPossibility]
>
> #The author with the most points on them would be considered the program's guess.
> Match = max(AUTHOR_SCOREBOARD)
>
> print AUTHOR_SCOREBOARD
>
> if Match == DJMachalePossibility:
> print "The author should be D.J. Machale."
>
> if Match == SuzanneCollinsPossibility:
> print "The author should be Suzanne Collins."
>
> if Match == RichardPeckPossibility:
> print "The author should be Richard Peck."
>
>
> ------------------------------------------------------------------------------
> Hopefully, there won't be any copyright issues. Like someone said, this should be fair use. The problem I'm having is that it always gives Suzanne Collins, no matter what example is put in. I'm really sorry that the code isn't very clean. Like I said, it was rushed and I have little experience. I'm just desperate for help as it's a bit too late to change projects, so I have to stick with this. Also, if it's of any importance, I have to be able to remove or add any of the "average letters per word/average letters per sentence/average words per sentence things" to test the program at different levels of strictness. I would GREATLY appreciate any help with this. Thank you!
>
1. When you calculate averages, you should be using floating
point divide.
avg = float (a) / b
2. When you subtract two values, you need an abs, because
otherwise min () will hone in on the negative values.
3. Realize that having Match agree with more than one is not
that unlikely.
4. If you want to vary what you call strictness, you're really
going to need to learn about functions.
--
DaveA
More information about the Python-list
mailing list