Re: [Tutor] Help with Guess the number script
On Mar 10, 2014, at 11:18 PM, Dave Angel wrote: > Scott W Dunning Wrote in message: >> > > Would you please stop posting in html? I don’t know what you mean? I just use the text for my email provider. It’s not html? I types up the code I had in the script.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On Mar 10, 2014, at 11:18 PM, Dave Angel wrote: Where are you guys using the forum? Through google? I was using that at first but someone complained about something that google does and told me to get it through my email. That’s what I’m doing now and I get bombarded with about 500 emails a day but I’m still doing something wrong? I’d rather go though a site to view the forum anyways, it seems way easier then having to sort through hundreds of emails. I’m not trying to be rude I’m just wondering, I don’t want to be irritating people if by doing something wrong. Thanks again for all of your help! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On 11/03/14 07:42, Scott W Dunning wrote: On Mar 10, 2014, at 11:18 PM, Dave Angel wrote: Where are you guys using the forum? Personally I use the news feed from Gmane.org I read it in Thunderbird (or occasionally via a newsreader on my smartphone/tablet). You can also read it online in a browser if you must. ...someone complained about something that google does > and told me to get it through my email. Its possible to get Google to behave properly but it seems like its usually easier to switch to a mail tool... :-( That’s what I’m doing now and I get bombarded with about 500 emails a day Not from the tutor list though. It only has a few mails normally - less than 50 most days. But you should be abler to set up auto filtering rules on your mail tool to route all the tutor mails into a separate folder for reading later. Also if you turn on threading in your mail tool for that folder you'll get them grouped by subject. I’d rather go though a site to view the forum > anyways, I can never understand why people like web forums, they are so limited in functionality. But if you must go that way try the gmane feed. Tutor is in (with a zillion other Python lists) under comp.python.tutor. it seems way easier then having to sort through > hundreds of emails. See the comments above, also consider digest mode. I’m not trying to be rude I’m just wondering, It's ok, everyone is allowed preferences. :-) What tends to irritate folks is the HTML content which different readers display differently. Especially the indentation which often gets lost. You need to explicitly go into your mail tool options and select "plain text" rather than "rich text" or "HTML" which will likely be the default. You can often tell if you don't have plain text because you will have options to change font, size, colour etc. You can't do any of that with plain text. But modern mail tools often make it very difficult to set plain text, especially web based ones. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On 11/03/14 04:07, Scott W Dunning wrote: On Mar 8, 2014, at 3:57 AM, spir mailto:denis.s...@gmail.com>> wrote: And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together. I think that was me rather than Denis, but that's irrelevant... This is what I have right now, obviously it’s not working. I’ve been playing around with it but I’m just not seeing where I’m going wrong. Any suggestions are greatly appreciated! def print_hints(secret, guess): if guess < 1 or guess > 100: print print "Out of range!" print if guess < secret: print print "Too low!" if guess > secret: print print "Too high!" OK so far, you don't need all the print statements but that's just a style issue. (You could just insert '\n' characters instead.) if guess < secret - 10 or guess > secret - 10: This is the right idea for cutting the line count but you have the comparison values wrong. Look back to earlier emails, you are repeating the same error as before. Manually think through what happens in the line above if guess == secret. And then once you get that fixed you can rewrite using the chained comparison trick to tidy it up. ie if not (lower limit < guess > upper limit): HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] educational
MICHAEL BASHAGI wrote: [Please send your posts to the mailing list, not individual posters. Thank you.] > But the PIL doesn't work in my version of Python, i use Python 3.4 If you are still working on this: as Tim hinted there is a fork of PIL called Pillow with installers for Python 3.4. See https://pypi.python.org/pypi/Pillow/2.3.0 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On 03/11/2014 04:32 AM, Scott W Dunning wrote: On Mar 8, 2014, at 11:50 AM, Scott dunning wrote: And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together. I’m having a hard time doing that because the guess can be either too low or too high but it is always either cold, warm, or on fire. I can’t figure out how to make it work with out splitting the cold, warm and on fire under two branches, one too low and one too high. Any suggestions? Well, what is the meaning of "absolute value"? Cold, warm, or on fire depend on the distance between both numbers, secret and guess, right? d ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++ on python
CC'ing the list Please use ReplyAll when responding. > > From: Gabriele Brambilla >To: Alan Gauld >Sent: Tuesday, 11 March 2014, 12:54 >Subject: Re: [Tutor] c++ on python > > > >I think (because I've not received the code yet) I will receive the source >code (.c or .cpp file) >and I want to compile it in the way to use it and maybe make small changes. So >I think I want >to embed the code as a Python module (but it's not properly a library). > >What is your experience level with C/C++? Are you familiar with building C/C++ libraries or even object files? There are documents and tools to help you turn C code into Python libraries but that's really outside the scope of the tutor list. About the dependencies I am not so sure as before. >So I mistaken the list? which one is the right one? >I suspect you may want a different list. But you will need to be clear about >what you are trying to do. It's still not clear what exactly this source code will be. Is it a library or a program? Do you think is it better that I install a C compiler and I don't use python? I use Anaconda... >You will need a C compiler regardless, if you receive C source code. Python cannot work with C in source format, only after it is compiled. But that does not mean you can't use Python to work with it, and that is probably easier than trying to write your whole application in C++ - especially if you are not already fluent in C++. I've no experience of Anaconda but it looks like it might be hard to find an equivalent in the C++ world, especially if you have already written a lot of Python/Anaconda code. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On 03/11/2014 09:57 AM, Alan Gauld wrote: On 11/03/14 04:07, Scott W Dunning wrote: On Mar 8, 2014, at 3:57 AM, spir mailto:denis.s...@gmail.com>> wrote: And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together. I think that was me rather than Denis, but that's irrelevant... You are right! d ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On 03/11/2014 05:07 AM, Scott W Dunning wrote: On Mar 8, 2014, at 3:57 AM, spir wrote: Well done. And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together. So below is what I finally came up with that works. I’m trying to condense it to half the number of lines like Denis suggested. I was hoping to clarify a couple things if you guys don’t mind…. I wanna make sure I understand how this code is working. So, from what I gather it first checks to see if the ‘guess’ is out of range and if that is false it continues to the next ‘if’ statement checking wether it’s too low. Now this is where I’m not 100% sure if the too low ‘if’ statement is false does it skip everything that is nested below it (you are cold, warm, on fire) and go to the ‘if statement checking if it’s too high? And now say the too low ‘if’ statement is true, because it’s an ‘if’ the code does not stop it continues but when it gets to the elif the code stops? def print_hints(secret, guess): if guess < 1 or guess > 100: print print "Out of range!" print I think here if the condition is true, you could just quit the function (return), no? The rest does not make much sense, I guess... if guess < secret: print print "Too low!" if guess < secret - 10: print "You are cold!" print print "Sorry please try again." print print elif guess < secret - 5: print "You are warmer!" print print "Sorry please try again." print print else: print "You're on fire!!" print print "Sorry please try again." print print if guess > secret: print print "Too high!" if guess > secret + 10: print "You are cold!" print print "Sorry please try again." print print elif guess > secret + 5: print "You are warmer!" print print "Sorry please try again." print print else: print "You're on fire!!" print print "Sorry please try again." print print This is what I have right now, obviously it’s not working. I’ve been playing around with it but I’m just not seeing where I’m going wrong. Any suggestions are greatly appreciated! def print_hints(secret, guess): if guess < 1 or guess > 100: print print "Out of range!" print if guess < secret: print print "Too low!" if guess > secret: print print "Too high!" if guess < secret - 10 or guess > secret - 10: print "You are cold!" print print "Sorry please try again." print print elif guess < secret - 5 or guess > secret - 5: print "You are warmer!" print print "Sorry please try again." print print else: print "You're on fire!!" print print "Sorry please try again." print print Below, the "temperature" hint and low/high hint are logically independant. The first one depends on the distance between secret and guess numbers, the second one depends on their relative values (greater/smaller). And the second hint (low/high) only makes sense iff the player did not win, meaning iff not "on fire!". However, both are related to the difference. Conceptually, after having passed the test out-of-range, I would start with something like: diff = guess - secret # (we know guess is in range) # temperature hint dist = abs(diff) if dist == 0: ... on fire! return elif dist < 5: ... # (we know secret was not found) # high/low hint neg = diff < 0 ... As an exercise, you could write each kind of hint in a separate tool func, and call each one only when relevant. Denis ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] c++ on python
I answer in the text 2014-03-11 9:32 GMT-04:00 ALAN GAULD : > CC'ing the list > Please use ReplyAll when responding. > > > -- > *From:* Gabriele Brambilla > *To:* Alan Gauld > *Sent:* Tuesday, 11 March 2014, 12:54 > *Subject:* Re: [Tutor] c++ on python > > I think (because I've not received the code yet) I will receive the source > code (.c or .cpp file) > and I want to compile it in the way to use it and maybe make small > changes. So I think I want > to embed the code as a Python module (but it's not properly a library). > > What is your experience level with C/C++? > Are you familiar with building C/C++ libraries or even object files? > I know C/C++, I am not able to do everything but I think that I can compile a simple programm with object files and libraries > There are documents and tools to help you turn C code into Python > libraries > but that's really outside the scope of the tutor list. > > About the dependencies I am not so sure as before. > So I mistaken the list? which one is the right one? > > I suspect you may want a different list. But you will need to be clear > about what you are > trying to do. It's still not clear what exactly this source code will be. > Is it a library or a program? > A program. it should use only standard C++ libraries. > Do you think is it better that I install a C compiler and I don't use > python? I use Anaconda... > > You will need a C compiler regardless, if you receive C source code. > Python cannot work with C in source format, only after it is compiled. > But that does not mean you can't use Python to work with it, and that is > probably easier than trying to write your whole application in > C++ - especially if you are not already fluent in C++. > Yes I would prefer to use Python as much as possible. What do you mean about using Python to work with it? How do you usually do? I've no experience of Anaconda but it looks like it might be hard to find > an equivalent > in the C++ world, especially if you have already written a lot of > Python/Anaconda code. > > Alan Gauld > Author of the Learn To Program website > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > Thanks Gabriele ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Trying to read dBase files
Greetings. I'm new to python and want to use it to create an application to read one or more dbase files, manipulate some data, and create a new file. I am using Python 3.3. I did some google searches and found something called dbfpy to read dbase, so I downloaded and installed it. The examples show. >From dbfpy import dbf When I do this I get the following error: >>> from dbfpy import dbf Traceback (most recent call last): File "", line 1, in from dbfpy import dbf File "C:\Python33\lib\site-packages\dbfpy\dbf.py", line 260 print repr(_rec) ^ SyntaxError: invalid syntax My assumption is that this module is written for an earlier release of Python? Some other google searches suggested using microsofts ODBC drivers for dBase, so I downloaded and installed pyodbc and got this: Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:12:08) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import pyodbc >>> cnxn = pyodbc.connect('DRIVER={Microsoft Access dBASE Driver};SERVER=localhost;DATABASE={Q:\TWS\MAILMERGE\BIL8.DBF}') Traceback (most recent call last): File "", line 1, in cnxn = pyodbc.connect('DRIVER={Microsoft Access dBASE Driver};SERVER=localhost;DATABASE=Q:\TWS\MAILMERGE\BIL8.DBF') pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') Do I have the driver name incorrect? Al Bull ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to read dBase files
On 11/03/14 18:39, Al Bull wrote: I'm new to python and want to use it to create an application to read one or more dbase files, manipulate some data, and create a new file. You could also try the Dabo project, it is an IDE for building DBase like apps. I think it supports reading Foxpro(aka DBASE) files. I am using Python 3.3. I did some google searches and found something called dbfpy to read dbase, so I downloaded and installed it. File "C:\Python33\lib\site-packages\dbfpy\dbf.py", line 260 print repr(_rec) ^ SyntaxError: invalid syntax You are using Python 3.3 so print is a function. You need to use print( repr(_rec) ) My assumption is that this module is written for an earlier release of Python? That may be true too, but your problem is in the print line. Some other google searches suggested using microsofts ODBC drivers for dBase, so I downloaded and installed pyodbc and got this: Yes thats possible too if you are on a Windows platform. Python 3.3.4 (v3.3.4:7ff62415e426, Feb 10 2014, 18:12:08) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. import pyodbc cnxn = pyodbc.connect('DRIVER={Microsoft Access dBASE Driver};SERVER=localhost;DATABASE={Q:\TWS\MAILMERGE\BIL8.DBF}') Traceback (most recent call last): ... Do I have the driver name incorrect? Sorry can't help with that one! HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Trying to read dBase files
Alan Gauld Wrote in message: > On 11/03/14 18:39, Al Bull wrote: > > > >> I am using Python 3.3. I did some google searches and found something >> called dbfpy to read dbase, so I downloaded and installed it. >> >>File "C:\Python33\lib\site-packages\dbfpy\dbf.py", line 260 >> print repr(_rec) >> ^ >> SyntaxError: invalid syntax > > You are using Python 3.3 so print is a function. > You need to use > >print( repr(_rec) ) > >> My assumption is that this module is written for an earlier release of >> Python? > > That may be true too, but your problem is in the print line. Which is in the dbfpy code. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On Mar 11, 2014, at 1:49 AM, Alan Gauld wrote: > > Not from the tutor list though. It only has a few > mails normally - less than 50 most days. > Actually now that you say that most of the emails are coming through the reg python-lists, not the tutor section. I guess I should just unsubscribe from python-lists because my questions are going through the tutor section for awhile. >> I’m not trying to be rude I’m just wondering, > > What tends to irritate folks is the HTML content > which different readers display differently. > Especially the indentation which often gets lost. > You need to explicitly go into your mail tool > options and select "plain text" rather than > "rich text" or "HTML" which will likely be the > default. > > You can often tell if you don't have plain text > because you will have options to change font, > size, colour etc. You can't do any of that with > plain text. But modern mail tools often make it > very difficult to set plain text, especially > web based ones. > Yeah, I had no idea that my messages were coming through in HTML, nor what it looked like until someone sent me a section showing me what it looked like, I can see how that would be frustrating. I’m using the mail app on my macbook pro, any suggestions on how to stop it from going out as html? Do I need to change the font? Also, I think last time I sent a section of my code I copy and pasted it from my script, could that be the problem? Thanks again! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On Mar 11, 2014, at 8:06 PM, Scott W Dunning wrote: [mega byte] >> > Yeah, I had no idea that my messages were coming through in HTML, nor what it > looked like until someone sent me a section showing me what it looked like, I > can see how that would be frustrating. > > I’m using the mail app on my macbook pro, any suggestions on how to stop it > from going out as html? Do I need to change the font? Also, I think last > time I sent a section of my code I copy and pasted it from my script, could > that be the problem? > > Thanks again! Simple. In Mail Preferences -> Composing -> Message Format -> Plain Text (Your setting is probably currently Rich Text.) -Bill ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help with Guess the number script
On Mar 11, 2014, at 7:50 PM, William Ray Wing wrote: > > Simple. In Mail Preferences -> Composing -> Message Format -> Plain Text > (Your setting is probably currently Rich Text.) > Got it, hopefully that helps. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor