Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python Help

Name: Anonymous 2008-12-04 2:04

Ok /prog/, so I've been awfully busy learning python lately and I was wondering if you could help me.I've been working on my side project lately and I came across this interesting little math problem and was hoping that some skilled /prog/grammers could help me out with an elegant solution.

People can rate cheeseburgers on my website with a star rating of 0-5 stars in whole stars. Five would be mighty tasty and zero would be disgusting. I want to show the average of everyone’s ratings of a single cheeseburger to the closest half star. I have already calculated the average rating as a float (star_sum) and the total number of people that rated the particular cheeseburger (num_raters). The result would then be stored as a float in a variable named “stars.”

here is my python code:

# round to one decimal place and
# separate into whole and fractional parts
parts = str(round(star_sum/num_raters, 1)).split('.')
whole = int(parts[0])
frac = int(parts[1])
if frac < 3:
___frac = 0
elif frac > 7:
___frac = 0
___whole += 1
else:
___frac = 5
# recombine for a star rating rounded to the half
stars = float(str(whole)+’.'+str(frac))


Does anybody have a better solution for me?

Name: Anonymous 2008-12-04 2:16

Your CODE
It is not FORCEFULLY IDENTED ( OF )

Name: Anonymous 2008-12-04 2:45

Use the decimal module.

Name: Anonymous 2008-12-04 3:24

This just in: Nobody cares how you implement something as long as it works.

Name: Anonymous 2008-12-04 7:38

Name: Anonymous 2008-12-04 7:43

I’ve updated my solution to:

stars = round(star_sum*2/num_raters)/2

I knew there was a way to do this mathematically, I just couldn’t remember how. I suppose the same trick would work for rounding to thirds, fourths, etc. Thanks so much to r, Christopher Finke, and Bob for the better approach.

lol

Name: Anonymous 2008-12-04 8:06

ENTERPRISE CHEESEBURGER-ORIENTED WEB 2.0 APPROACH

Name: Anonymous 2008-12-04 8:28

>>6
I’ve updated my solution to:

stars = round(star_sum*2/num_raters)/2

I knew there was a way to do this mathematically, I just couldn’t remember how. I suppose the same trick would work for rounding to thirds, fourths, etc. Thanks so much to r, Christopher Finke, and Bob for the better approach.

Name: Anonymous 2008-12-04 8:55

>>5
You need help.

Name: Anonymous 2008-12-04 14:29

you should just count halfstars instead

Name: Anonymous 2008-12-04 15:48

>>5
Fuck, I raged so hard I had a heart attack.

Name: Anonymous 2008-12-04 16:42

Fail at programming, suck some cock, get bought out for millions. WEB 2.0

Name: Anonymous 2008-12-04 17:04

I wish I was a cute blonde caucasian female, that would make my programming career so much easier.

Name: Anonymous 2008-12-04 17:08

>>13
you too ;_;

Name: Anonymous 2008-12-04 19:46

I wish I was an acne-scarred male-to-female transsexual, that would make my programmer career so much easier.

Name: Anonymous 2008-12-04 20:23

>>15
I know you're probably joking, but the CS industry has an alarming rate of M->F transsexuals, more so than any other industry.

Name: Anonymous 2008-12-04 20:32

>>16
Because we're all jailhouse gay due to the lack of contact with real women and we idolize traps like Bridget and due to homophobic bullying being a nerd is pretty much the same as being gay or wishing to be the little girl.

Hey, it's not like we're allowed to use our penises. Might as well get it cut off. It's not like it's doing us any good.

Name: Anonymous 2008-12-04 20:36

>>15
What the fuck man... I wouldn't wish this pain on any other person.

Name: Anonymous 2008-12-04 20:51

>>15
M.U.L.E. was fun

Name: Anonymous 2008-12-04 23:14

then you can experience the pleasure of being cummed inside

Name: Anonymous 2008-12-05 1:38

A family walks into a talent agency. It's a father, mother, son, daughter and dog. The father says to the talent agent, "We have a really amazing act. You should represent us."

The agent says, "Sorry, I don't represent family acts. They're a little too cute."

The mother says, "Sir, if you just see our act, we know you would want to represent us."

The agent says, "OK. OK. I'll take a look."

The Father then raises his hands and exclaims: "Wait until you see this, it's a family act, a song and a dance, an animal act, audience participation... it's got everything! First off my wife and I come out on the stage, I'm wearing a tux, she's in a full gown. I take off the tux and lift up her gown... I then begin fucking her in the ass like no tomorrow while she sings the national anthem. Then my son comes out drops his pants shoves his cock in his mother's mouth, and she keeps singing... although now it's more of a hum. While this is happening my daughter comes out stark naked with a beach ball. she balances it on her nose and starts clapping her hands together, see this is where the animal part comes in because my daughter is retarded, she barks like a seal. After i blow my load in my wife's asshole, I jam my fist up there and do a ventriloquist routine all the while my son is still face fucking my wife while she goes into "Oh, Canada". Now my retard daughter brings a trunk up on stage and throws on a burkha. I then pull my fist out of my wife's ass, give it a good lick, go out into the audience and find the biggest pile driving black guy i can find. I have him come up on stage and put on a pig mask and drape himself in the american flag and proceed to anally violate my retarded pre-teen daughter. I then down a bottle of laxative, shit on stage rub the shit all over my face, and sing amazing grace in the best slave voice i have. My wife bites my son's cock off and draws a swastika in blood on her bare chest, then puts on a kkk hood and strap on and fucks me while i sing my favorite negro spirituals. After the black guy blows his load all over my retarded daughter and proceeds to fuck my adolescent son's decimated body, cause you know brothers, they can never get enough ass... my dog comes out..."

The talent agent then goes "Well what on Earth does the dog do?"

the man licks his lips and says "Well the dog comes out wearing a little pink tutu, honks a few horns, and jumps through a hoop."

For the longest time, the agent just sits in silence. Finally, he manages, "That's a hell of an act. What do you call it?"

And the father says, WEB 2.0

Name: Anonymous 2008-12-05 3:01

>>21
ENTERPRISE SOLUTIONS

Name: Anonymous 2008-12-05 7:17

>>21
I smirk'd.

Name: Anonymous 2009-03-06 11:52

Gown I then begin fucking her in   some way but   start by watching   the SICP video   lectures and then   click the mouse   and keyboard consumes   quite a bit   and I found   this works in   sbcl asdf defsystem.

Name: Trollbot9000 2009-07-01 7:56

Says Well the dog you saw Haskell.

Name: Anonymous 2011-02-04 18:33

Don't change these.
Name: Email:
Entire Thread Thread List