- Strength to Increase Rep
- +7
- Strength to Decrease Rep
- -1
- Upvotes Received
- 29
- Posts with Upvotes
- 24
- Upvoting Members
- 16
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
- PC Specs
- Debian Linux stock kernel 2.4.25 on a Dell Inspiron XPS
Re: While Python offers flexible [I]container[/I] data structures, such as lists and dictionaries, it is occasionally helpful to create our own. Suppose, for example, that we wanted to create a data structure with two dictionaries: one for key-value pairs where len(key) is even, and one for key-value pairs where len(key) is … | |
Re: Write a simple calculator in Python. The program should accept an arithmetic expression from the command-line, then recursively parse it to produce a numerical value. Like many programming projects, this one can be done in phases: i) First, make the program parse only basic arithmetic. This means expressions that use … | |
Re: Hi EriCartman13, If you want to create a random number between 1 and 100, the conventional way of doing that in Python is:[CODE]import random x = random.randint(1,100)[/CODE]I would swap this code in and remove the for loop. The resulting program creates a random integer between 1 and 100, assigns that … | |
Re: You mean something like this?[CODE]import re f = dict() f["compile"] = re.compile f["findall"] = re.findall f["match"] = re.match pattern = f["compile"]("[\\w]+")[/CODE]This works for me. | |
Re: [I]...and that is .exe program that can be run on different machines.[/I] That's not necessarily true. Compiling a C/C++ program does not create a universal executable that can be installed on any machine. Whether the executable will work on your friend's machine depends on (a) what the program does, and … | |
Re: Hi ram.patil, A Hardy-Ramanujan number is a number which can be expressed as the sum of two positive cubes in exactly two different ways. For example, 1729 is equal to the sum: 1^3+12^3 - or alternatively, to the sum: 9^3+10^3 - but not to any other sums of positive cubes. … | |
Hi guys, I'm trying to learn the principles of artificial intelligence. I just finished coding up a belief net and a corresponding EM algorithm that learns the CPTs for latent nodes using training data (if you're unfamiliar with the lingo, you're probably going :eek: right now). While the program (written … | |
Here's something of mine that might actually be useful: a Python implementation of the K-means clustering algorithm. I wrote something similar last year in Java for a school project, and decided to rewrite it in Python this summer for practice. The purpose of the algorithm is to discover internal structure … | |
Re: Hi Ene Uran, There are two ways of doing this. The first way: use the textvariable option in the Label constructor to set the Label text to the value of a StringVar maintained elsewhere in your program. Then, in your callback function, change the value of the StringVar and the … | |
Re: Hi eleonora, Statements like this:[CODE]board[(x,y)] == "R"[/CODE]with a double equals sign (==) only test to see whether the value at (x,y) is "R"; that statement does not [I]assign[/I] "R" to board[(x,y)], which is what you want to do. Instead, use board[(x,y)] = "R" and it should remember the moves. Also … | |
Re: Hi Avner .H., I can't help you with your first problem, other than to say "why not put the Bash code in a Bash script?" which I guess is not an option for you, or else you would have done it. However, I can help with the second item: grabbing … | |
Hi all, Have you ever heard of "Petals Around the Rose?" It's a logic puzzle. The way it works is, I roll five dice, then tell you what the "score" is for this round. I can repeat this for you as many times as you want. It's your job to … | |
[URL="http://www.bitstorm.org/gameoflife/"]Life[/URL] is a "game" or cellular automaton - an evolving computational state system - developed by a Cambridge mathematician named John Conway. The idea is simple: start with a board of dimensions (x,y). Populate the board with an initial pattern of occupied and empty cells. In every turn, the rules … | |
Suppose you are a medical researcher studying diabetes. Your boss has given you a big chart of data from diabetes patients. Each row of the chart has information for one patient. Each column of the chart is a health-related statistic, such as height, weight, age, blood pressure, cholesterol level, etc. … | |
Here's a cute little encipher/decipher program with a Tkinter GUI I wrote a while back. It's an implementation of a derivative of the Vigenere algorithm; the algorithm is taken from Laurence Smith's Cryptography: The Science of Secret Writing, Amazon link here. It's a dated book (and the technique itself is … | |
Re: You could always make a .exe file that calls the Python script, then rename that to .scr, right? | |
Re: Hi jmroach, You're going to want to use an sqlite [URL="http://www.sqlite.org/pragma.html"]pragma statement[/URL]. A pragma statement lets you query database meta-data or in some cases alter the behavior of the database. The pragma that gives you column headers is called "table_info." In the example you gave below, you would use it … | |
Re: Hi gusbear, Are you using the Zelle graphics module? If you are, I think you should try the following strategy. Create a GraphWin, then in one of the corners make a button by drawing a rectangle, and inside it printing "Compute" or something like that. The API for the graphics … | |
Re: Hi rysin, Unless there's a high-level python module that takes care of chat-type stuff for you (and if there is, I don't know about it), you're going to have to learn how to use client and server sockets to send data from one computer to another. An example is given … | |
Re: Hi Edwards8, It turns out that PIL will let you read pieces of an image file in sequence without loading the entire thing into memory. Fred Lundh has a post about it on a python mailing list [URL="http://mail.python.org/pipermail/image-sig/1999-April/000713.html"]here[/URL]. I don't know if this will work for TIFs, but you can … | |
Re: Hi zachabesh, Can't you just use os.path.getsize()? You call it with the name of the file as an argument. | |
Re: Hi sidbizzle, So if I am understanding your code correctly, you are trying to set up a program that prints a welcome prompt with a menu, then allows the user to deposit or withdraw from an account. The amount of money in the account is stored in acctHist.data, along with … | |
Re: Hi linux, Yes, that is definitely possible. I've done something similar from within both pygame and Tkinter (I used Tkinter to design a GUI program for map editing). You would want to begin by creating a pygame Surface for each of the 10x10 image tiles, then stick all your Surfaces … | |
Hi all, I add a pygame implementation of the Game of Life to the Code Snippets section. I was actually kind of surprised that we didn't already have one in there! The program only has about 60 lines of code, but I buttressed that with a lot of comments and … | |
Re: Hi nish88, Search in this forum for "game of life." | |
Hi all, Are there any python modules which contain functions for getting the roots of a quartic (degree 4) polynomial? I don't think NumPy has anything like it, and I [I]really[/I] don't want to enter the equations in by hand. Thanks. | |
Re: Hi RMartins, This has less to do with Python and more to do with mathematics, but I'll say it anyway. As jrcagle said, 10**20 is a huge number of iterations to perform. Lucky for you, you won't need many more than 10**7. Actually, you'll only need to perform 10,015,005 computations, … | |
Re: Hi Carlo Gambino, The straightforward way of doing this is:[CODE=python]g = [ 1, 2, 3, 4 ] h = [] for i in range(len(g)+1)[1:]: h.append(g[i-1]+i) print h[/CODE]Alternatively, you could just use a list comprehension:[CODE=python]print [ g[i-1]+i for i in range(len(g)+1)[1:] ][/CODE]Hope this helps! | |
Re: Hi StepIre, You could use the pickle module, which serializes and saves data structures, effectively allowing you to skip the whole messy business of file parsing. Example:[CODE=python]import pickle # If you want to store a dictionary in a file... d = { "a":"aardvark", "b":"ball", "c":"centurion" } f = open("somefile.dat", "w") … | |
Re: Hi trihaitran, Use the "template method" software design pattern! Here's how it works: we're going to split that function of yours across two different functions in two different classes: a superclass with a "template method" and a subclass with a "hook method." The template method in the superclass contains all … |