Posts
 
Reputation
Joined
Last Seen
Ranked #1K
Strength to Increase Rep
+7
Strength to Decrease Rep
-1
100% Quality Score
Upvotes Received
29
Posts with Upvotes
24
Upvoting Members
16
Downvotes Received
0
Posts with Downvotes
0
Downvoting Members
0
8 Commented Posts
2 Endorsements
Ranked #621
Ranked #355
~182.32K People Reached
PC Specs
Debian Linux stock kernel 2.4.25 on a Dell Inspiron XPS
Favorite Forums
Favorite Tags
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
23
34K
Member Avatar for vegaseat

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 …

Member Avatar for vegaseat
20
18K
Member Avatar for EriCartman13

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 …

Member Avatar for bumsfeld
-1
4K
Member Avatar for bumsfeld

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.

Member Avatar for Kyss
0
238
Member Avatar for Micko

[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 …

Member Avatar for darkside2205
0
321
Member Avatar for ram.patil

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. …

Member Avatar for TrustyTony
0
2K
Member Avatar for G-Do

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 …

Member Avatar for Gael Varoquaux
0
330
Member Avatar for G-Do

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 …

Member Avatar for woooee
2
1K
Member Avatar for Ene Uran

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 …

Member Avatar for vegaseat
0
3K
Member Avatar for eleonora

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 …

Member Avatar for TrustyTony
0
3K
Member Avatar for Avner .H.

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 …

Member Avatar for sneekula
0
798
Member Avatar for G-Do

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 …

0
848
Member Avatar for G-Do

[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 …

0
1K
Member Avatar for G-Do

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. …

2
1K
Member Avatar for G-Do

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 …

0
219
Member Avatar for a1eio

You could always make a .exe file that calls the Python script, then rename that to .scr, right?

Member Avatar for Stefano Mtangoo
0
2K
Member Avatar for jmroach

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 …

Member Avatar for weisburd
0
23K
Member Avatar for gusbear

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 …

Member Avatar for hobbz86
0
133
Member Avatar for rysin

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 …

Member Avatar for EAnder
0
96
Member Avatar for Edwards8

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 …

Member Avatar for woooee
0
428
Member Avatar for zachabesh

Hi zachabesh, Can't you just use os.path.getsize()? You call it with the name of the file as an argument.

Member Avatar for zachabesh
0
126
Member Avatar for sibdizzle

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 …

Member Avatar for G-Do
0
186
Member Avatar for linux

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 …

Member Avatar for linux
0
139
Member Avatar for G-Do

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 …

Member Avatar for nish88
0
110
Member Avatar for nish88
Member Avatar for G-Do

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.

Member Avatar for jrcagle
0
96
Member Avatar for RMartins

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, …

Member Avatar for G-Do
0
82
Member Avatar for Carlo Gambino

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!

Member Avatar for jrcagle
0
141
Member Avatar for StepIre

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") …

Member Avatar for StepIre
0
126
Member Avatar for trihaitran

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 …

Member Avatar for G-Do
0
113