2,190 Posted Topics

Member Avatar for qingmui

Not recursion, but proof of concept only (and done quickly). Returns zero if it is a palindrome. [CODE]def ispalindrome(pal): return sum([0 if x == pal[(ctr+1)*-1] else 1 for ctr, x in enumerate(pal) if ctr < len(pal)/2]) sentence = "Red Roses run no risk, sir, on nurses order." sentence_clean = ''.join(c.lower() …

Member Avatar for vegaseat
0
780
Member Avatar for FreezeBlink

The simpliest way is an easygui or Tkinter/PMW dialog box with one button. However, this is something found on the web long ago. It is probably also possible to do with ncurses.[CODE]import termios, sys, os #import termios, TERMIOS, sys, os TERMIOS = termios def getkey(): fd = sys.stdin.fileno() old = …

Member Avatar for richieking
0
14K
Member Avatar for vbx_wx

Only one for loop would be used because you want to access the same relative position in each string. Also, do not use "i" as a variable name as it looks too much like the number 1. [CODE]def cromo(a, b): inc = 0 if len(a) != len(b): print "both strings …

Member Avatar for woooee
0
207
Member Avatar for durhamandy

You have to iterate through the entire array, whether you write you own or use a built in method. Since you also want the max also, go through the array once, storing any number that is larger than the current maximum, along with it's position.

Member Avatar for vegaseat
0
246
Member Avatar for vbx_wx

Some print statements should clear up some things. And note that your __add__ function will yield an error but that is something to address after you get this part working. [CODE] class mylist: def __init__(self,l): self.data = l; def __add__(self,l): self.data = self.data + l def __repr__(self): return self.data x …

Member Avatar for vbx_wx
0
95
Member Avatar for dbphydb

I have no idea which output file you are talking about or which statement writes the header a second time. If you are talking about this segment of the code, [CODE] outfile = open(dst_file, "wb") outfile.write(content) outfile.close() [/CODE] "wb" creates/overwrites to a new file each time the function is called. …

Member Avatar for woooee
0
179
Member Avatar for leazell

Add a little more to the print statements to tell you where you are. [CODE]def prime(n): print "-"*30 print "starting prime with n =", n if n == 0: print("Equals zero, This is not a Prime number") answer = 0 if n == 1: print("Equals one, This is not a …

Member Avatar for Thisisnotanid
0
6K
Member Avatar for radc

This stripped down version appears to work for me, but it is rewritten because it was too difficult to tell the i, l, and 1's apart, let alone what the variables with nonsense names are supposed to contain. [CODE]import wx class TestFrame( wx.Frame ): def __init__( self ): wx.Frame.__init__ ( …

Member Avatar for richieking
0
658
Member Avatar for LogicallyInsane

That is a fairly standard menu. An example only partially completed and tested. [CODE]import math import sys def get_number(func_name): try: arg = int(input("Enter number of degrees for function %s: " % func_name)) return arg except: print("Sorry, we can only calculate for integer degrees") sys.exit(1) def sin_funct(): name = "Sine" val …

Member Avatar for LogicallyInsane
0
153
Member Avatar for nosehat

[URL=http://effbot.org/librarybook/zipfile.htm]Effbot's example[/URL] for reading a file into memory, which can then be written anywhere you like as long as the files are not huge. [CODE]import zipfile file = zipfile.ZipFile("samples/sample.zip", "r") for name in file.namelist(): data = file.read(name) print name, len(data), repr(data[:10]) [/CODE]

Member Avatar for nosehat
0
166
Member Avatar for deepakgupta2186

There is no reason to use a list, or if you do, don't create a new dictionary on every pass through the loop. [CODE]dict1={} n=input("Enter the number of contacts : ") for i in range(0,n): name1=raw_input("Enter your name: ") num=input("Enter your phone number: ") if name not in dict1: dict1[name] …

Member Avatar for TrustyTony
0
177
Member Avatar for kuchi

The wiki at python.org is always a good place to start any search [URL]http://wiki.python.org/moin/WebFrameworks[/URL].

Member Avatar for snippsat
0
132
Member Avatar for Brickmack

Python does not have a keypress capture so you have to use one provided by the system like termios. [CODE]import termios, sys, os TERMIOS = termios def getkey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO new[6][TERMIOS.VMIN] = 1 new[6][TERMIOS.VTIME] = 0 …

Member Avatar for richieking
0
271
Member Avatar for -ordi-

[QUOTE]In: 07:34 08:55 10 20 08:25 09:00 10 20 Out: 08:25 09:00 10 20 07:34 08:55 10 20 [/QUOTE]For a reverse order sort like this, you simply compare for greater instead of lesser, which Python sorts will do with the reverse=True parameter set. Do you also want to take into …

Member Avatar for TrustyTony
0
140
Member Avatar for Python_Doofus

Draw it out first, then program each part individually and then put them together. To get you started, here is part of the right-most picture. Continue with a separate function to draw the other half (columns side), and then look at a way to combine them. It you can not …

Member Avatar for woooee
0
130
Member Avatar for mqtgirl

Try [URL=http://wwwsearch.sourceforge.net/mechanize]mechanize[/url] and see if it will work for you. [URL=http://stockrt.github.com/p/emulating-a-browser-in-python-with-mechanize/]An example[/URL].

Member Avatar for woooee
0
155
Member Avatar for _Nestor

If you want to print from the word to the end of the line, use index. This untested code will tell you if a word is found. You can then use .join to print out what you want.[CODE]for line in logfile: words_list = line.split(): for word in KEYWORDS: ## or …

Member Avatar for pensaf
-1
212
Member Avatar for brundlefly

If you store the prefixes in a list: [CODE] prefix1=userInput1[:3] prefix2=userInput2[:3] prefix3=userInput3[:3] ## ## becomes prefix_list = [prefix[:3] for prefix in userInput] [/CODE]You can then clean up the if() statements: [CODE] if prefix1==networkList[0] or prefix2==networkList[0] or prefix3==networkList[0]: msg+= "\n"+" vodafone ""\t" # # + the other if() statements becomes message_tup …

Member Avatar for brundlefly
0
110
Member Avatar for sanjcee

To start you off, look for redundant statements, like all of the if/elif at the end of the program that basically do the same thing. They can be replaced by a simple dictionary of values. [CODE]## The following 3 lines can be deleted for this example #u = 1 #optimism …

Member Avatar for richieking
0
110
Member Avatar for yellowkaiq

It does not appear that you are using physical dimensions, since there are no numbers < 11, but this will print 5 random combinations. [CODE]import random shapes = ['square', 'triangle', 'circle', 'left'] physical = range(1, 11) angles = range(10, 91, 10) print " shape phy angle" for j in range(5): …

Member Avatar for woooee
0
2K
Member Avatar for jice
Member Avatar for jice
0
161
Member Avatar for Python_Doofus

This is the last time I am explaining technique. Start out with something specific that works and expand to the general. Take this code which shows one specific set of 3, and then a second set, and expand so it will print one entire row, then expand so it will …

Member Avatar for richieking
0
226
Member Avatar for lewashby

I'm not sure about the question is, but try this code and see if it clarifies things.[CODE]name = 'Jack' print '"name" is this memory address', id(name) def say_hello(): print ('Hello ' + name + '!') def change_name(new_name): name = new_name print "name is now", name print '"name" is this memory …

Member Avatar for TrustyTony
0
124
Member Avatar for chiochiosane

First, add some print statements for testing: [CODE]# add a colomn of 0 >>>for j in range(len(my_list)): row = my_list[j] row.append(0) print "row now =", j, row # Add a row of 0 >>>for i in range(len(my_list)): colomn=my_list[i] colomn.append(0) print "column now =", i, colomn # # a matrix (list …

Member Avatar for woooee
0
74
Member Avatar for furret

It would be something along these lines, see [URL=http://hetland.org/writing/instant-python.html]"Functions" here[/URL]: [CODE]def CoM_positions(value_in): if some_condition: ## or whatever CoM_return = CoM(value_in) print CoM_return, value_in return CoM_return return_value = find_positions(positions) better_values= CoM_positions(return_value) print better_values [/CODE]

Member Avatar for woooee
0
134
Member Avatar for ccandillo

There are two problems that I can see. It should be "root.mainloop" and there is no config statement for load menu so only the empty "menubar" is displayed. Also, note the inconsistent use of master and self.master. I did not test with any of the commented lines included. If they …

Member Avatar for woooee
0
353
Member Avatar for halien

It looks like you have 13 lines of normal text, by which I mean that you could open it normally and read the first 13 lines normally, and count the bytes to skip. Then close the file, open as binary and skip the number of bytes that contained text, but …

Member Avatar for woooee
0
117
Member Avatar for kk12345

There is an example in the turtle graphics demo of the Python docs that come with Python.

Member Avatar for TrustyTony
0
375
Member Avatar for liran

It appears the the backslash is being escaped by Python. Try repr(the_string) as output and see if it helps.

Member Avatar for Gribouillis
0
2K
Member Avatar for Zohaq

Tab is not necessary. Try this code, which will accept anything, letters, numbers, equal signs, etc. [CODE]ltr_str = raw_input("Enter 10 letters ") while len(ltr_str) != 10: ltr_str = raw_input("Enter 10 letters and 10 letters only ") printed = 0 for ltr in ltr_str: ## access each individually print ltr, printed …

Member Avatar for woooee
0
177
Member Avatar for KA2806

[QUOTE]i[I] made a start but i cant make it work with the colour nor adding size dimensions.[/QUOTE]That is a little vague. Post one function with a description of what you want it to do. Also in getWidth() and getHeight() it will error out in Python 2.X if a non-digit is …

Member Avatar for woooee
0
80
Member Avatar for coco08

Using x,y coordinates confuses things IMHO. You can just number each square and enter one number for that square. This also simplifies keeping track of moves as you can use a single list with one element for each square on the board.

Member Avatar for dekalbxxx
0
556
Member Avatar for jrp370

You don't need recursion for this. Are you sure you are not supposed to sort in reverse order, i.e. maximum value is first. You can think of recursion as a while loop, with a function calling itself instead of looping.

Member Avatar for Gribouillis
0
2K
Member Avatar for acrocephalus

Three more links: [url]http://hetland.org/writing/instant-python.html[/url] [url]http://python-eggs.org/[/url] [url]http://www.doughellmann.com/PyMOTW/[/url] (more of a reference)

Member Avatar for Dylan Solarsh
0
239
Member Avatar for rx21825

Hundreds of records is not much in today's world so you can read each file into a dictionary and go from there. A simple example to associate the two files because I am too tired to do more today. You can omit some of the unnecessary records from the dictionary …

Member Avatar for TrustyTony
0
2K
Member Avatar for keltik

I'm not sure what you are asking, but see if this helps: [CODE]## last line under main() print "points for one", point_one.x, point_one.y print "points for two", point_two.x, point_two.y # # and add this additional function to Triangle and call it def print_points(self): print self.A.x, self.A.y print self.B.x, self.B.y print …

Member Avatar for TrustyTony
0
153
Member Avatar for dmurder

If you are using Python3.X, then input will return a string which is always greater than 100, print type(score) to see which class it belongs to.

Member Avatar for richieking
0
150
Member Avatar for dmurder

Please don't post 54 lines of untested crap here and ask up to clean up your mess. Test each function individually. For example: What happens when you enter 2 students here: [CODE]def getNumber(number): number = input('Enter a number between 2 and 30: ') while number <=2 or number >=30: print'You …

Member Avatar for richieking
0
130
Member Avatar for SomeKittens

You don't have any button or other widget variable "Quit". You possibly want to store the memory address for the buttons in a list and then use button_list[3].clicked() as it is the last/fourth button created. Using the local symbol table is somewhat obfuscated code IMHO.

Member Avatar for Gribouillis
0
272
Member Avatar for Swedenrock

You can do that in two ways, the second way is usually preferred because everything is contained in the class: [CODE]import random class Kortlek(): def __init__(self,colors=["blue ", "yellow ", "red "], \ forms=["triangel", "circle ", "square "], \ numbers=[1, 2, 3], grades=[1, 2, 3]): self.cardList = [] self.playerCardList = [] …

Member Avatar for TrustyTony
0
121
Member Avatar for Swedenrock

You also should test for length before you draw cards: [CODE]def cards(self): if len(self.cardList) > 5): for a in random.sample(self.cardList, 6): [/CODE]

Member Avatar for woooee
0
143
Member Avatar for furret

[QUOTE]Hey, I've got an array full of random numbers[/QUOTE]It depends on how many levels are in the array. Generally, you would flatten the array into a single level list, and operate on that. If you want to keep the original structure, then you have to test for the type. If …

Member Avatar for woooee
0
102
Member Avatar for xtra333

The code works fine for me on Slackware Linux. What are you using for input, and what output do you get?

Member Avatar for richieking
0
149
Member Avatar for twohot

The advantages of Multiprocessing are: it does not use a GIL and it can use multiple cores if you are on a multi-core machine. This means that it is usually faster, but it ultimately comes down to what you understand and can use.

Member Avatar for woooee
0
117
Member Avatar for c-tech

It appears the the zero is being read as minutes and the one as the hour. I doubt any of the cron programmers allowed for someone entering "01" instead of just "1".

Member Avatar for c-tech
0
206
Member Avatar for KMC

Generally you begin with the input [QUOTE]The user will enter a molecule with each atom individually (CO2 would be entered as): C O O...The user should continue to be asked for more molecules until they enter a blank line.[/QUOTE]Next would be the dictionary you spoke of, sign-->mass, and looking up …

Member Avatar for KMC
0
79
Member Avatar for patrickgormally

Start by using [URL=http://www.google.com/search?client=opera&rls=en&q=python+turtle+triangle&sourceid=opera&ie=utf-8&oe=utf-8]a turtle triangle[/URL] for the tree, add a small rectangle for the tree stump, and then modify the triangle to look more tree like.

Member Avatar for woooee
0
3K
Member Avatar for xtra333

Note also that you start with zero, not one, and your zero replaces 21, and your 21 replaces 16. One problem is that you generate 26 numbers, zero through 25, with only 25 spaces to hold them. I have no other advice because "And here is what the square is …

Member Avatar for woooee
0
124
Member Avatar for longlongsilver

It depends somewhat on what widget you want to set, but generally you can use configure. This is something I have lying around from somewhere and added a configure to change the background and foreground of the button when the top button is pressed. Another example is [URL=http://www.ferg.org/thinking_in_tkinter/tt080_py.txt]here[/URL]. You also …

Member Avatar for richieking
0
309
Member Avatar for bretthay93

There have been several examples on Daniweb alone [url]http://www.daniweb.com/forums/thread246963.html[/url]

Member Avatar for bretthay93
0
313

The End.