[Tutor] extreme basics
This is extremely weird, I think. Here is a tiny program: from math import * from Numeric import * x=[0]*10 for counter in rangelen((x)): x[counter]=counter*0.1 print x Here is what I get: [0.0, 0.10001, 0.20001, 0.30004, 0.40002, 0.5, 0.60009, 0.70007, 0.80004, 0.90002] What on Earth is going on with those decimals at the end? Is this a floating point thing? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
> Can Python be used to mine an Openoffice spreadsheet > or database? There are Python - OO links. I've never used them but a Google search will throw them up I'm sure. But the easiest way is probably either to export the data as a CSV file and use the csv module or to put the data in a database and use OO or Python to access the databae directly. The latter approach is better if you have a large number of records or if there are many relationships in your data. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
Thanks, Alan. Good to know. I think I'll explore both routes, as it will at least get me some practice with Python. Oh, wait. Can Python be used to mine an Openoffice spreadsheet or database? Nick On Sun, Jan 4, 2009 at 3:45 PM, Alan Gauld wrote: > > "Nick Scholtes" wrote > > mind. For instance, I work with some groups that rescue homeless animals. >> It >> would be wonderful if I could compile a thorough database, then mine the >> data and create graphs to troubleshoot issues. As an example, we might >> find >> that more homeless animals show up in "x" location, or at "xyz" time of >> year. This could help in re-focuses efforts more efficiently. >> > > While I'm a big fan of Python and its powers I'm also a big fan of using > the right tool for the job. I'd start with a spereadsheet, possibly with a > database back end. Excel or OpenOffice would be adequate for that kind > of data mining and graphing. > > Python would be more suited (IMHO) for more complex searches where > you aren't able to simply filter or aggregate values. > > Just a thought, > > Alan G. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Art: http://www.coroflot.com/bellsoffreedom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
Thanks, Alan. Good to know. I think I'll explore both routes, as it will at least get me some practice with Python. Nick On Sun, Jan 4, 2009 at 3:45 PM, Alan Gauld wrote: > > "Nick Scholtes" wrote > > mind. For instance, I work with some groups that rescue homeless animals. >> It >> would be wonderful if I could compile a thorough database, then mine the >> data and create graphs to troubleshoot issues. As an example, we might >> find >> that more homeless animals show up in "x" location, or at "xyz" time of >> year. This could help in re-focuses efforts more efficiently. >> > > While I'm a big fan of Python and its powers I'm also a big fan of using > the right tool for the job. I'd start with a spereadsheet, possibly with a > database back end. Excel or OpenOffice would be adequate for that kind > of data mining and graphing. > > Python would be more suited (IMHO) for more complex searches where > you aren't able to simply filter or aggregate values. > > Just a thought, > > Alan G. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Art: http://www.coroflot.com/bellsoffreedom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] RE Silliness
On Sun, 04 Jan 2009 14:09:53 -0500 bob gailer wrote: > Omer wrote: > > I'm sorry, burrowed into the reference until my eyes bled. > > > > What I want is to have a regular expression with an optional ending of > > "" > > > > (For those interested, > > urlMask = r"http://[\w\Q./\?=\R]+"; > > is ther version w/o the optional ending.) > > > > I can't seem to make a string optional- only a single character via > > []s. I for some reason thuoght it'll be ()s, but no help there- it > > just returns only the . Anybody? > > > urlMask = r"http://[\w\Q./\?=\R]+()?" > > From the docs: ? Causes the resulting RE to match 0 or 1 repetitions of > the preceding RE. ab? will match either 'a' or 'ab'. > > Maybe Omer had not noted that a sub-expression can be grouped in () so that an operator (?+*) applies on the whole group. Denis -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Documentation and top matter
"wormwood_3" wrote #!/usr/bin/env python #- """ My awesome purpose. """ author = "My Name" date_started = "2001-01-01" version = 0.1 #- IMPORT STUFF REST OF CODE This format is still readable and distinct, but by putting the information into attributes, they are accessible in an interpreter, Neat I hadn't thought of that. The other thing thats often useful is to use your version control tool to insert the keystrings for you. They virtually all have similar features for auto-insertting the version number, filename, update comments and dates. For example in SCCS ( I know, but I had the docs handy! :-): %M% = Module name %R% - Release Number %L% - Level number %E% - Date newest delta was created etc etc. I don't use SVN but I'm sure it will have similar capabilities. Just some thoughts, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
"Nick Scholtes" wrote mind. For instance, I work with some groups that rescue homeless animals. It would be wonderful if I could compile a thorough database, then mine the data and create graphs to troubleshoot issues. As an example, we might find that more homeless animals show up in "x" location, or at "xyz" time of year. This could help in re-focuses efforts more efficiently. While I'm a big fan of Python and its powers I'm also a big fan of using the right tool for the job. I'd start with a spereadsheet, possibly with a database back end. Excel or OpenOffice would be adequate for that kind of data mining and graphing. Python would be more suited (IMHO) for more complex searches where you aren't able to simply filter or aggregate values. Just a thought, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] WinMerge -- I'm Impressed
"Wayne Watson" wrote It took me 15 minutes to merge the two in an acceptable manner. I just tried the result and am happy to report that it works as expected. Glad to hear it, there are many such merge tools around some more automated than others. Doing this by inspection of printed lists or holding two windows (in IDLE, Notepad or whatever) In emacs or vim you could do the merge in place and edit the merge display. Its a standard feature of both. (I think eclipse can do it too although I haven't used it for that...). search the respective help systems for diff... And for those who prefer command line tools sdiff on *nix will do the job too. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Top posters to tutor list for 2008
I think I find it most interesting that the greatest percent is still under 15% and then it tapers rapidly. I'm curious what % of people posted 5 or less messages... perhaps it will become a personal project somewhere down the road ;) -Wayne On Fri, Jan 2, 2009 at 7:28 AM, Kent Johnson wrote: > On Fri, Jan 2, 2009 at 8:13 AM, Sander Sweers > wrote: > > On Fri, Jan 2, 2009 at 13:52, Kent Johnson wrote: > >> Or ask more questions, that works too! > > > > So you and Alan ask the most questions ;-) > > No, that honor goes to Dick Moores. He is in the top 10 in 4 of the > last 5 years! > > > Thanks to all the Tutors for year of great support :-) > > You're welcome, we couldn't do it without you! > > Kent > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- To be considered stupid and to be told so is more painful than being called gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness, every vice, has found its defenders, its rhetoric, its ennoblement and exaltation, but stupidity hasn't. - Primo Levi ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
Thank you all so much for the great information so far. I really appreciate it. I'm going over it now. And sample code helps TON! That really allows me to see what happens with a program. In reference to wormwood_3's question about my intentions for data mining; I want to know this stuff in general, but I also have some applications in mind. For instance, I work with some groups that rescue homeless animals. It would be wonderful if I could compile a thorough database, then mine the data and create graphs to troubleshoot issues. As an example, we might find that more homeless animals show up in "x" location, or at "xyz" time of year. This could help in re-focuses efforts more efficiently. I'm going to start going over those links and sample code, but beware! I'll probably be dropping a bunch more questions soon! Take care, Nick On Sun, Jan 4, 2009 at 2:10 PM, Kent Johnson wrote: > On Sun, Jan 4, 2009 at 1:25 PM, Nick Scholtes wrote: > > Hi, > > I'm still very, very new to Python and programming. I was wondering if > > anyone can point me in the right direction. > > Welcome! > > > As I gradually learn Python, one of the things I want to be able to do is > > take a database, run queries and extract information and then graph that > > information visually to see patterns in the data. Where should I start? > > Does Python do this? If not, what language is used for this? > > Yes, you can do this in Python. > > Python has a standard for interfacing to databases called DB-API: > http://www.python.org/dev/peps/pep-0249/ > > You will have to obtain and install a DB-API module for the specific > database you want to query: > http://wiki.python.org/moin/DatabaseInterfaces > > The docs for the individual modules tend to be sparse because they > follow the DB-API. > > For graphing, there are several options: > http://wiki.python.org/moin/NumericAndScientific/Plotting > > I recommend matplotlib. > > You should probably start with a basic Python tutorial, though; both > DB-API and matplotlib will be difficult if you don't have a basic > understanding of Python. Pick a tutorial here: > http://wiki.python.org/moin/BeginnersGuide/NonProgrammers > > Kent > -- Art: http://www.coroflot.com/bellsoffreedom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Documentation and top matter
While PEP 8 and PEP 257 provide ample helpful information on the recommended ways to document classes, functions, and comments within code, I am having a hard time finding recommendations on how to document scripts by way of top matter. For example, I used this format for a while: #!/usr/bin/env python #- # Name:my_cool_name # Purpose: My awesome purpose. # # Author: My Name # # Started: 01/01/01 #- # IMPORT STUFF REST OF CODE This made it *really* easy to see what was going on as soon as you opened the file. Then I started shifting to something more like this: #!/usr/bin/env python #- """ My awesome purpose. """ author = "My Name" date_started = "2001-01-01" version = 0.1 #- IMPORT STUFF REST OF CODE This format is still readable and distinct, but by putting the information into attributes, they are accessible in an interpreter, by external tools, etc. Also putting the purpose in the first docstring allowed for use of .__doc__. But are there more generally accepted means of defining this information that are highly readable? I have also seen attributes in the form of "__author__ = 'My Name'", for which I found some discussion on comp.lang.python ( http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-10/0128.html ). Recommendations? ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
On Sun, Jan 4, 2009 at 1:25 PM, Nick Scholtes wrote: > Hi, > I'm still very, very new to Python and programming. I was wondering if > anyone can point me in the right direction. Welcome! > As I gradually learn Python, one of the things I want to be able to do is > take a database, run queries and extract information and then graph that > information visually to see patterns in the data. Where should I start? > Does Python do this? If not, what language is used for this? Yes, you can do this in Python. Python has a standard for interfacing to databases called DB-API: http://www.python.org/dev/peps/pep-0249/ You will have to obtain and install a DB-API module for the specific database you want to query: http://wiki.python.org/moin/DatabaseInterfaces The docs for the individual modules tend to be sparse because they follow the DB-API. For graphing, there are several options: http://wiki.python.org/moin/NumericAndScientific/Plotting I recommend matplotlib. You should probably start with a basic Python tutorial, though; both DB-API and matplotlib will be difficult if you don't have a basic understanding of Python. Pick a tutorial here: http://wiki.python.org/moin/BeginnersGuide/NonProgrammers Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
I have done some data analysis work with Python, mostly with MySQL databases. Just as easy as the examples Eric mentioned with SQLite. All depends on what database you have to work with. Did you have any in mind or just wondering about data mining and Python in general? Regarding graphing, I have had great luck with using pylab ( http://www.scipy.org/PyLab ). Here is a simple example to create graphs of a thing being counted per unit: # Grab the needed module: from pylab import * def GraphData(time_and_count): """ Creates graph image of counts per time. """ # Set axis labels and their properties: x = xlabel('Time') setp(x, fontweight='bold') y = ylabel('Count') setp(y, fontweight='bold') # Plot: plotted = plot(time_and_count.keys(), time_and_count.values(), '--') setp(plotted, marker='s') title('Count over Time') grid(True) savefig('results.png', dpi=100) # Make a test dictionary of counts per time: time_and_count = dict(enumerate('4 5 3 4 6 7 8 9 3'.split())) # Make a graph: graphData(time_and_count) If all goes well, you should end up with a file "results.png" in the dir you ran this script. There is a LOT more you can do with pylab, but this sort of function should get you going for simple graphs. ___ Samuel Huckins Homepage - http://samuelhuckins.com Tech blog - http://dancingpenguinsoflight.com/ Photos - http://www.flickr.com/photos/samuelhuckins/ AIM - samushack | Gtalk - samushack | Skype - shuckins From: Eric Dorsey To: Nick Scholtes Cc: tutor@python.org Sent: Sunday, January 4, 2009 2:32:12 PM Subject: Re: [Tutor] Python - Data Mining? Hi Nick, I don't know about the graphing portion of your question, but yes Python does interact very well with databases. I have been working on a workout tracking program the last two months or so, and I'm new to programming. I'd highly recommend SQLite as a built-in database solution. I know it's included in Python version 2.5 which is what i'm currently running. You can call it at the top of your program with "import sqlite3", then you can run queries and create tables, etc. Here is some example code of SQLite usage in my program: #create the database, or connect if it already exists conn = sqlite3.connect('workoutstats.db') #create a variable called cursor to use, since its easier than typing out conn.cursor() all the time.. cursor = conn.cursor() #create a table cursor.execute(''' CREATE TABLE WR (id INTEGER PRIMARY KEY, reps SMALLINT(1000), weight SMALLINT(1000), exer VARCHAR(30), date DATE) ''') #query the WR table, feeding it the 'srch' variable which fills in where the SQL has a ? cursor.execute( "SELECT SUM(REPS) FROM WR WHERE EXER=?", (srch,) ) -Eric On Sun, Jan 4, 2009 at 11:25 AM, Nick Scholtes wrote: Hi, I'm still very, very new to Python and programming. I was wondering if anyone can point me in the right direction. As I gradually learn Python, one of the things I want to be able to do is take a database, run queries and extract information and then graph that information visually to see patterns in the data. Where should I start? Does Python do this? If not, what language is used for this? Thank you very much, Nick -- Art: http://www.coroflot.com/bellsoffreedom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- (e) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python - Data Mining?
Hi Nick, I don't know about the graphing portion of your question, but yes Python does interact very well with databases. I have been working on a workout tracking program the last two months or so, and I'm new to programming. I'd highly recommend SQLite as a built-in database solution. I know it's included in Python version 2.5 which is what i'm currently running. You can call it at the top of your program with "import sqlite3", then you can run queries and create tables, etc. Here is some example code of SQLite usage in my program: #create the database, or connect if it already exists conn = sqlite3.connect('workoutstats.db') #create a variable called cursor to use, since its easier than typing out conn.cursor() all the time.. cursor = conn.cursor() #create a table cursor.execute(''' CREATE TABLE WR (id INTEGER PRIMARY KEY, reps SMALLINT(1000), weight SMALLINT(1000), exer VARCHAR(30), date DATE) ''') #query the WR table, feeding it the 'srch' variable which fills in where the SQL has a ? cursor.execute( "SELECT SUM(REPS) FROM WR WHERE EXER=?", (srch,) ) -Eric On Sun, Jan 4, 2009 at 11:25 AM, Nick Scholtes wrote: > Hi, > I'm still very, very new to Python and programming. I was wondering if > anyone can point me in the right direction. > > As I gradually learn Python, one of the things I want to be able to do is > take a database, run queries and extract information and then graph that > information visually to see patterns in the data. Where should I start? > Does Python do this? If not, what language is used for this? > > Thank you very much, > Nick > > > -- > Art: http://www.coroflot.com/bellsoffreedom > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > -- (e) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 59, Issue 16
Gerard Kelly wrote: > Hi everyone, I'm a python noob but I have an ambitious (for me) goal: I > want to make a simple program that allows you to hear combinations of > notes according to a vector of frequencies. > > Does anybody know any module that allows you to input a frequency in Hz > and returns a sound with that frequency, and lets you do that with > multiple frequencies, so that you can build chords? The recipe linked below plays sounds composed of a fundamental and a few harmonics. It requires Pygame and NumPy. http://osdir.com/ml/culture.people.kragen.hacks/2007-11/msg0.html It is out of date, though. I had to change 'Numeric' to 'numpy' and 'Int16' to 'int16' to get it to work. Moreover NumPy doesn't seem to work with Python 2.6. You can also use TkSnack (http://www.speech.kth.se/snack/). Check the example named 'notescale' that comes with the module: it defines a function that receives a frequency as an input and plays a sound; there is also a graphical interface. Regards, Emmanuel ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] RE Silliness
Omer wrote: I'm sorry, burrowed into the reference until my eyes bled. What I want is to have a regular expression with an optional ending of "" (For those interested, urlMask = r"http://[\w\Q./\?=\R]+"; is ther version w/o the optional ending.) I can't seem to make a string optional- only a single character via []s. I for some reason thuoght it'll be ()s, but no help there- it just returns only the . Anybody? urlMask = r"http://[\w\Q./\?=\R]+()?" From the docs: ? Causes the resulting RE to match 0 or 1 repetitions of the preceding RE. ab? will match either 'a' or 'ab'. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] WinMerge -- I'm Impressed
Title: Signature.html Several months ago I took a Python (2.4) program (A) distributed by our sponsors and made a number of mods. About 4 months later the sponsors updated it (B) to operate under 2.5 and added a number of changes of their own. I dreaded the thought of merging A into B, so have delayed it. Last night I finally decided WinMerge might have sufficient features to make this simple. It did. It took me 15 minutes to merge the two in an acceptable manner. I just tried the result and am happy to report that it works as expected. Doing this by inspection of printed lists or holding two windows (in IDLE, Notepad or whatever) open and looking for changes to merge (which really what WinMerge does) would have taken me hours. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "What killed the electric car? Expensive batteries did." -- Physics for Future Presidents, Richard A. Muller Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Add all natural numbers that are multiples of 3 and 5
Alan Gauld wrote: "bob gailer" wrote Also consider that the sum of consecutive integers between 1 and n is n*(n+1)/2. Calculate that for 1..333 then multiply by 3 Calculate that for 1..199 then multiply by 5 add those Calculate that for 1..66 then multiply by 15 subtract that from the total Ooh, that's sneaky! I haven't seen that before. Guess you did not study number theory. Standard algorithm. Google sum of consecutive integers. Regarding Project Euler - I believe one of the objectives is to find solutions that are not just brute force. Some of the problems can be solved by brute force but will take too much computer time. Sphere Online Judge www.spoj.pl is even more rigorous in that it runs your program and if run time is too long the solution is considered not correct. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python - Data Mining?
Hi, I'm still very, very new to Python and programming. I was wondering if anyone can point me in the right direction. As I gradually learn Python, one of the things I want to be able to do is take a database, run queries and extract information and then graph that information visually to see patterns in the data. Where should I start? Does Python do this? If not, what language is used for this? Thank you very much, Nick -- Art: http://www.coroflot.com/bellsoffreedom ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] RE Silliness
I'm sorry, burrowed into the reference until my eyes bled. What I want is to have a regular expression with an optional ending of "" (For those interested, urlMask = r"http://[\w\Q./\?=\R]+"; is ther version w/o the optional ending.) I can't seem to make a string optional- only a single character via []s. I for some reason thuoght it'll be ()s, but no help there- it just returns only the . Anybody? Thx, Omer. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Add all natural numbers that are multiples of 3 and 5
"bob gailer" wrote Also consider that the sum of consecutive integers between 1 and n is n*(n+1)/2. Calculate that for 1..333 then multiply by 3 Calculate that for 1..199 then multiply by 5 add those Calculate that for 1..66 then multiply by 15 subtract that from the total Ooh, that's sneaky! I haven't seen that before. Took me a couple of reads through to figure out how it worked :-) -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] repply
prasad rao wrote: hi I got it right. >>> z=[] >>> for x in range(1000): if divmod(x,3)[1]==0:z.append(x) if divmod(x,5)[1]==0:z.append(x) >>> sum(set(z)) 233168 Instead of using the set function you could just use an elif in your for loop. >>> z=[] >>> for x in range(1000): if divmod(x,3)[1]==0:z.append(x) elif divmod(x,5)[1]==0:z.append(x) >>> sum(z) 233168 or as somebody else suggested use an OR operator >>> z=[] >>> for x in range(1000): if (divmod(x,3)[1]==0) or (divmod(x,5)[1]==0): z.append(x) >>> sum(z) 233168 just some variations... On an other wise correct anwser. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Sound, frequencies and chords
On Sun, Jan 4, 2009 at 8:07 AM, Mr Gerard Kelly wrote: > Hi everyone, I'm a python noob but I have an ambitious (for me) goal: I > want to make a simple program that allows you to hear combinations of > notes according to a vector of frequencies. > > Does anybody know any module that allows you to input a frequency in Hz > and returns a sound with that frequency, and lets you do that with > multiple frequencies, so that you can build chords? Have you found this page? http://wiki.python.org/moin/PythonInMusic Several items in the "Playing & creating sound" and following sections look promising: audiolab Loris MusicKit PyMedia Pyper PySndObj PythonSound/Csound Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] repply
On Sun, Jan 4, 2009 at 14:18, prasad rao wrote: z=[] for x in range(1000): > if divmod(x,3)[1]==0:z.append(x) > if divmod(x,5)[1]==0:z.append(x) sum(set(z)) > 233168 This can be done in one line of python. >>> sum([x for x in range(1000) if x %3 == 0 or x % 5 == 0]) 233168 Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] repply
hi I got it right. >>> z=[] >>> for x in range(1000): if divmod(x,3)[1]==0:z.append(x) if divmod(x,5)[1]==0:z.append(x) >>> sum(set(z)) 233168 I am sorry if this is outside the perimeter of this list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Sound, frequencies and chords
Hi everyone, I'm a python noob but I have an ambitious (for me) goal: I want to make a simple program that allows you to hear combinations of notes according to a vector of frequencies. Does anybody know any module that allows you to input a frequency in Hz and returns a sound with that frequency, and lets you do that with multiple frequencies, so that you can build chords? I've googled around but I can't find what I'm looking for. I don't want MIDI since from what I know it only lets you choose from 12 notes (C, C#, D, D#) etc., but I want the full range of frequencies. If you can let me know about anything, I'd really appreciate it, thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] project euler
prasad rao schreef: > hello! > I got it 266333. > My code== > > t=0 > for x in range(1000): > if divmod(x,3)[1]==0:t+=x > if divmod(x,5)[1]==0:t+=x > t=266333 > > Am I correct in comprehention of the problem? Not entirely: you're counting numbers that are multiples of both 3 and 5 double, which is not the intention. BTW, instead of divmod(x, 3)[1] you can use x % 3. divmod() is nice if you need both quotient and remainder, but if you only need the remainder the % operator is simpler. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] project euler
hello! I got it 266333. My code== t=0 for x in range(1000): if divmod(x,3)[1]==0:t+=x if divmod(x,5)[1]==0:t+=x t=266333 Am I correct in comprehention of the problem? Prasad ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Add all natural numbers that are multiples of 3 and 5
On Sun, Jan 4, 2009 at 3:43 AM, Benjamin Serrato wrote: > I think it does what I wanted it to do, but Kent pointed out I wanted > it to do was a false solution. So, I can create a list of all common > multiples below 1000, sum them, subtract them from 266 333. Or, what > I prefer, create a list of all multiples, checking against that list > for a multiple before adding a new multiple. But, I don't know how to > work with lists so I'll be back in a day or two. Removing this double counting can be done easily if you realize that the double multiples are exactly 15 and its multiples. -- André Engels, andreeng...@gmail.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor