Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 06-19-2012, 08:16 PM   #541
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

here is a programming problem i am having a problem with. i have data for 1300 football games. for each game i have the spread, and what the result was compared to the spread. it is set up as a list of lists now [(game1_spread, game1_result_compared_to_spread), (game2_spread, game2_result_compared_to_spread), etc.]

i want to take this information and make a printout with these two pieces of data:

spread: game1_result_compared_to_spread==0/total_games_with_this_spread
spread2: game1_result_compared_to_spread==0/total_games_with_this_spread
etc. for each spread

how can i get this?
unluckyboy is offline   Reply With Quote
Old 06-19-2012, 09:09 PM   #542
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

okay did it i will post solution and appreciate feedback
unluckyboy is offline   Reply With Quote
Old 06-21-2012, 02:28 PM   #543
veteran
 
Acemanhattan's Avatar
 
Join Date: Jan 2007
Location: PDX Oregon
Posts: 2,465
Re: ** Python Support Thread **

Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?

Why when I am using that "New Window" does it automatically indent sentences that I don't think it should? For example I type the following for the first line:

outstanding_balance = int(raw_input("What is your outstanding balance?")

When I press enter it indents me about 7 tab spaces on the next line like:

outstanding_balance = int(raw_input("What is your outstanding balance?")
print "What is your outstanding balance?"


also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.

Edit to add: 2+2 isn't displaying the indent the way I'm intending to show it, imagine "print" starting directly under "raw_input"
Acemanhattan is online now   Reply With Quote
Old 06-21-2012, 04:28 PM   #544
veteran
 
Colombo's Avatar
 
Join Date: Feb 2005
Posts: 3,354
Re: ** Python Support Thread **

Quote:
Originally Posted by Acemanhattan View Post
Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?

Why when I am using that "New Window" does it automatically indent sentences that I don't think it should? For example I type the following for the first line:

outstanding_balance = int(raw_input("What is your outstanding balance?")

When I press enter it indents me about 7 tab spaces on the next line like:

outstanding_balance = int(raw_input("What is your outstanding balance?")
print "What is your outstanding balance?"


also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.

Edit to add: 2+2 isn't displaying the indent the way I'm intending to show it, imagine "print" starting directly under "raw_input"
Ok, for starters I'm not quite sure what you mean by "Python shell" and "New Window", but I can answer your other questions.

As for this line:
Code:
outstanding_balance = int(raw_input("What is your outstanding balance?")
The indent is happening because your parenthesis aren't balanced. You need one ")" to close the "raw_input(" function, and another ")" to close the "int(" function.

Quote:
also if I'm not mistaken my first command is saying that whatever the user inputs when prompted, it will be turned from a string into an integer correct? And the second command should print the prompt for the user, correct?

When I try to run that code I get a syntax error.
Yes you are correct. The int() function will convert an object (in this case a String) into an integer. Hint: Type "help(int())" in your python shell.

The reason you are getting an error could be for a few reasons. As I said before you need to close your open parenthesis. In addition, the int() function will only work on a properly formatted String.

Try the following:
int('1')
int('3.4')
int('two')
Colombo is offline   Reply With Quote
Old 06-21-2012, 05:22 PM   #545
Carpal \'Tunnel
 
Xhad's Avatar
 
Join Date: Jul 2005
Location: hatredcopter
Posts: 10,194
Re: ** Python Support Thread **

Quote:
Originally Posted by tyler_cracker View Post
preventing incest is gay? these kids today...
That reminded me of this exchange for some reason...
Xhad is online now   Reply With Quote
Old 06-22-2012, 12:02 AM   #546
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,918
Re: ** Python Support Thread **

hahahahha

Quote:
If that 6 were really a 9 and we were playing lowball and a 7 turns then I would have bottom pair which would be like top pair so I call
Quote:
A7 is not the nut seven-high, it's the 5th-nut Ace high. Duh.
MUCH LOVE FROM ME.
tyler_cracker is offline   Reply With Quote
Old 06-22-2012, 10:59 PM   #547
Pooh-Bah
 
fluorescenthippo's Avatar
 
Join Date: Apr 2005
Posts: 5,703
Re: ** Python Support Thread **

Quote:
Originally Posted by Acemanhattan View Post
Brand new to programming, just started going through the MIT opencourse and have some questions regarding Python.

If I open "Python Shell" and from there open "New Window" is this where I will be writing my programs? I then save it there and use the F5 function to run it in the shell correct?

Yea im doing this course too and thought the compiler they use seems kinda crappy unless im missing something.

i do the same as you but i dont know how to run the debugger from a new window and a few other things.
fluorescenthippo is offline   Reply With Quote
Old 06-23-2012, 12:46 AM   #548
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

god i hate elementtree and namespaces
unluckyboy is offline   Reply With Quote
Old 06-23-2012, 12:49 AM   #549
Carpal \'Tunnel
 
tyler_cracker's Avatar
 
Join Date: Apr 2005
Location: Shallow End OTKP
Posts: 13,918
Re: ** Python Support Thread **

heh, and you're just scraping it. imaging trying to write it!

Last edited by tyler_cracker; 06-23-2012 at 12:51 AM. Reason: or debug it. or refactor it. **** it, let's go back to gopher.
tyler_cracker is offline   Reply With Quote
Old 06-23-2012, 01:02 AM   #550
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

http://odds.sbrfeeds.com/events/?new...d&version=1.0&

can i get some help here, i have this page. how can i access the elements <side-name> using Xpath? how can i get access the element <side-name> where it's text equals "Jacksonville"
unluckyboy is offline   Reply With Quote
Old 06-23-2012, 01:05 AM   #551
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

i am trying tree.xpath("//{http://odds.sbrforum.com}side-name"), and root.xpath("//{http://odds.sbrforum.com}side-name"), tree.xpath("//{http://odds.sbrforum.com}:side-name"), and root.xpath("//side-name")

none work
unluckyboy is offline   Reply With Quote
Old 06-23-2012, 01:08 AM   #552
banned
 
Join Date: May 2012
Posts: 163
Re: ** Python Support Thread **

when i try to grab some random element and do tree.getpath(random_element) it gives me bull**** paths like /*/*[1]

what the hell is that
unluckyboy is offline   Reply With Quote
Old 06-23-2012, 05:10 AM   #553
aka Double Ice
 
Alex Wice's Avatar
 
Join Date: Jun 2007
Location: Twitter
Posts: 4,563
Re: ** Python Support Thread **

Quote:
Originally Posted by unluckyboy View Post
here is a programming problem i am having a problem with. i have data for 1300 football games. for each game i have the spread, and what the result was compared to the spread. it is set up as a list of lists now [(game1_spread, game1_result_compared_to_spread), (game2_spread, game2_result_compared_to_spread), etc.]

i want to take this information and make a printout with these two pieces of data:

spread: game1_result_compared_to_spread==0/total_games_with_this_spread
spread2: game1_result_compared_to_spread==0/total_games_with_this_spread
etc. for each spread

how can i get this?
I might not have understood your question btw.
Code:
def avgspread(sp,lt):
   #given a spread, and a list of games [ (spread,result),... ]
   # , return the average result compared to spread
   ans,ct = 0,0
   for i in lt:
       if i[0] == sp:
         ans += i[1]
         ct += 1
   return ans/float(ct)
Alex Wice is offline   Reply With Quote
Old 06-30-2012, 12:24 PM   #554
Pooh-Bah
 
fluorescenthippo's Avatar
 
Join Date: Apr 2005
Posts: 5,703
Re: ** Python Support Thread **

taking the MIT python course and came across this:

self.viruses = [x for x in newViruses]


can someone please explain to me how this is better than a typical for loop. I'm also uncertain as to what this does
fluorescenthippo is offline   Reply With Quote
Old 06-30-2012, 12:45 PM   #555
Carpal \'Tunnel
 
Xhad's Avatar
 
Join Date: Jul 2005
Location: hatredcopter
Posts: 10,194
Re: ** Python Support Thread **

That's called a list comprehension. In this case it's just copying the list. The equivalent as a for would be:

Code:
self.viruses = []
for x in newViruses:
    self.viruses.append(x)
The main advantage is code length and readability once you understand it; see my response to this post
Xhad is online now   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 01:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive