2,190 Posted Topics

Member Avatar for dliving

Add some print statements to see what is going on. I have added two in the following code.[CODE]from random import choice as rc def total(hand): aces = hand.count(11) t = sum(hand) if t > 21 and aces > 0: while aces > 0 and t > 21: t -= 10 …

Member Avatar for woooee
0
340
Member Avatar for David.lewing

I like using sets because they have a difference function.[CODE]alphabet = set("ABCDEFGHIJKLMNOPQRSTUVWXYZ") keyword = raw_input("Enter word ").upper() difference = alphabet.difference(keyword) ## sets are in hash order not in alphabetical order print "Hash sequence", difference, "\n" ## convert to a list so it can be sorted difference = list(difference) difference.sort() ## …

Member Avatar for woooee
0
373
Member Avatar for Joe Hart

[QUOTE]Once the user gives the program these parameters I would like to put it into the file below on line 11 and re save it as Compare # 2.asc.[/QUOTE]Apparently he does want to change the file posted, but since every tutorial covers file read/write, and no effort has been made …

Member Avatar for shadwickman
0
167
Member Avatar for apollo1492

l = abs(math.sqrt(2)(r*r)-(y*y)) Break this formula down into one calc per line and see where the error occurs, then print the variable and it's type(variable_name), and that should tell you where you went wrong. Also, it is not polite to use "i", "l",. or "o" as single letter variable names. …

Member Avatar for apollo1492
0
131
Member Avatar for lorayyne

I've modified you code by adding a function to do the "HTH" and "HTT" search. Since it is basically the same for 'H' and "T', one function can do it instead of two blocks of the same code . Note that the if heads/tails > 0 appears to be worthless, …

Member Avatar for woooee
0
213
Member Avatar for happymadman

I just skimmed your code, but it looks like a set() will do some of this for you. Using a builtin is easier and more reliable as it has been tested thousands of times. And cudos for figuring out the logic.[CODE]user_input = ["three", "four", "five", "six", "seven", "eight", "nine", "ten","one", …

Member Avatar for happymadman
0
147
Member Avatar for besktrap

[QUOTE]# changes the system's current dir. path to specified path[/QUOTE]It doesn't change the path, it adds that path to the list that Python searches. You can print sys.path if you want to see what it is. sys.path.append("/engine/lib/") ## or whatever it is import sprite_class and then sprite_obj = sprite_class.Sprite() to …

Member Avatar for besktrap
0
10K
Member Avatar for 136456

There are a few links to tutorials here. Qt seems to be the least documented of all the GUI toolkits for Python. [URL]http://www.python-eggs.org/?row=2[/URL]

Member Avatar for Ibn Saeed
0
269
Member Avatar for yemu

You will have to link them some way. You can combine them and sort as below, otherwise you will have to associate "yes" with zero, "i don't know" with one, etc. and reorder the list named results after sorting the labels list, but there isn't any reason why you have …

Member Avatar for vidaj
0
2K
Member Avatar for gotm

You can replace this:[CODE]#precondition to the actions checker def precondition(rule,state): if not blocked(rule,state,(allDirections[0])): if not blocked(rule,state,(allDirections[1])): if not blocked(rule,state,(allDirections[2])): if not blocked(rule,state,(allDirections[3])): if not blocked(rule,state,(allDirections[4])): if not blocked(rule,state,(allDirections[5])): if not blocked(rule,state,(allDirections[6])): if not blocked(rule,state,(allDirections[7])): return True else: return False ##--------------------------------------------------------- ## with (not tested) ## in other words, if any …

Member Avatar for gotm
0
142
Member Avatar for max.yevs

You should not be using "is" for comparison. It is used to test if the objects are the same. Guido, et al decided to store an internal list of 1-256 and reference the list for those numbers, so if you try: x=257 print x is 257 it will print False …

Member Avatar for max.yevs
0
207
Member Avatar for katamole

[QUOTE]Of course, I could do simple list comparison.[/QUOTE]However you organize it, you will have to compare all fields, i.e. cow_list[1] == sheep_list[1] = number of legs ==> ctr += 1 A hashed db or MySQL would only improve things if you were looking for all animals with 4 legs as …

Member Avatar for katamole
0
406
Member Avatar for henryxxll

You can also use divmod.[CODE]cnum = 21 cntnu = 1 currint = 1 #Begin Loop while cntnu == 1: currint = currint + 1 whole, remain = divmod(cnum, currint) if 0 == remain: cntnu = 0 print "Factorization Found." print whole, remain print currint, cnum else: print currint, "Factorization failed. …

Member Avatar for woooee
0
134
Member Avatar for khozamtho

You don't have to compile Python programs. It is interpreted/byte compiled, which basically means that it takes care of that. If you are just starting, I would suggest that you use Idle (comes with Python) until you are more comfortable with the language. A somewhat dated link [url]http://www.ai.uga.edu/mc/idle/index.html[/url]

Member Avatar for woooee
0
206
Member Avatar for rajasekhar1242

If you just want to convert text, there are tools like txt2pdf. You'll have to Google "text pdf" to see what runs on your OS.

Member Avatar for woooee
0
219
Member Avatar for bhanu1225

[QUOTE]take printout for the output of that program[/QUOTE]Do you mean save it in a file, send to the printer???[QUOTE]don't judge me because I'm a year 8![/QUOTE]My new sig: "Don't judge me because I'm a dumb-ass".

Member Avatar for scru
0
127
Member Avatar for Crinkly

[QUOTE]Can the edit wizard be altered to allow more than 4 packs to be used?[/QUOTE]And you will have to post your "edit wizard" code in order to get advice on how to change the program.

Member Avatar for Crinkly
0
81
Member Avatar for flip121

[QUOTE]I need the window to just refresh each time.[/QUOTE]I think you want root.update(). This is a simple example that I had lying around (click the start button to test).[CODE]from Tkinter import * import time ## --------------------------------------------------------- ## Demonstration of window update from FAQTs ## --------------------------------------------------------- class TestUpdate: def __init__(self, top): …

Member Avatar for flip121
0
1K
Member Avatar for katamole

Python (with batteries included) usually has a tested tool that will already do most common things. In this case, you want sets.[CODE]list1 = ['spam', 'eggs', 'bacon'] list2 = ['spam', 'ham', 'king richard'] set_1 = set(list1) set_2 = set(list2) ##matchitems(list1, list2) new_set=set_1.intersection(set_2) print new_set ## works either way print set_2.intersection(set_1) # …

Member Avatar for woooee
0
181
Member Avatar for ning2009

Do you just want to extract the values for the "MATERIAL" and "STEEL" or do you want all values under "MATERIAL"? Ditto for "FRAME" and "SHELL". You would test for "MATERIAL" or "FRAME" and then extract depending or which catagory it is, and use a dictionary to store the values, …

Member Avatar for ning2009
0
348
Member Avatar for skhan23

To start with, what do these mean and what is the order of their evaluation? Post your answer here if you want some help.[code]if (y>x and y<z)or(y<x and y>z): elif not(x!=y and y!=z):[/code]Since you have code, you can answer the first question by brute force. Set x and y to …

Member Avatar for adam1122
0
101
Member Avatar for leegeorg07

Something like this, using an interim list (untested). You could also put this in a function and return the word and counter the first time it is found.[CODE]logfile = open("logfile.txt", "r").readlines() KEYWORDS = ['test', 'text'] counterline = [] counter = 0 for line in logfile: junk_list = [] for word …

Member Avatar for woooee
0
115
Member Avatar for MartinIT2type

I think the problem is this line, if I understand you correctly. self.entryb["variable"] = self.bringout I think you can only use "StringVar()" and "textvariable=" with a button since there is no data entry or changing of the text, so change the code to something like[CODE] self.bringout = StringVar() self.bringout.set("0" ) …

Member Avatar for MartinIT2type
0
2K
Member Avatar for tech12

You might start with code tags (use the "#" icon) and then explain what the program you posted does, as it doesn't appear to make sense. Once you reach this line while R[0]<R[1]: it appears to be an infinite loop, but it's difficult to tell without proper indents. Basically, you …

Member Avatar for woooee
0
177
Member Avatar for gotm

For your example, the position is found, i.e. True is returned. Consider using "in" when comparing the two lists as that is the preferred method. The following illustrates this.[code]a = [ [0,1], [0,2], [1,2] ] b = [0, 2,] c = [2, 0] if b in a: print "b found" …

Member Avatar for woooee
0
124
Member Avatar for mangotango

Please put your code between code tags (the "#" icon) as no one will be able to run your program without proper indents. Generally, you use a control variable, in your case a string control variable, and the ".set " and ".get" methods to change the text or get the …

Member Avatar for sneekula
0
857
Member Avatar for gotm

Test each function individually by inserting print statements. Comment everything you don't want by using triple quotes """. Since you only have one while() loop, start here.[code]while not goal(state): print "=====>while not goal(state) ", goal(state), state for l in range(0, (len(allRules)), 1): if precondition((allRules[l]),state): applyRule((allRules[l]),state) else: print "Rule cannot be …

Member Avatar for woooee
0
96
Member Avatar for JeyC

A nice explaination of subprocess, which every programmer will use at one time or another, for future reference. [url]http://blog.doughellmann.com/2007/07/pymotw-subprocess.html[/url]

Member Avatar for woooee
0
119
Member Avatar for Malestryx

When someone enters pay rate or hours, what happens if they accidentally enter a letter or a float instead (pay rate is $9.99)? Or does the problem let you assume that only integers are entered,[code]pRate=raw_input("What is their hourly rate? ") intRate=int(pRate)[/code]

Member Avatar for woooee
0
1K
Member Avatar for Hatz2619

[quote]I can loop through all three questions ONE time and that's it.[/quote][CODE]while hours<1 or hours>60: hours=int(raw_input("Enter the number of hours[/CODE]If you entered 42 hours on the first pass, then hours still equals 42 and you will not enter the while loop. See Shibby's snippet. Use one infinite while() loop, to …

Member Avatar for Hatz2619
0
925
Member Avatar for toadzky

I use pyprocessing for this. For Python 2.5 it is pyprocessing, for 2.6 and above it is included in the distro and named multiprocessing. [url]http://pyprocessing.berlios.de/[/url] This will exit when you hit <Enter>.[CODE]import subprocess from processing import Process class test(): def funct_1(self, name): subprocess.Popen("ping www.google.com", shell=True) if __name__ == '__main__': CT=test() …

Member Avatar for vidaj
0
189
Member Avatar for srk619

It seems that all you have done is to copy code you found somewhere else. For example, what does this line that you posted mean and why would it be used in a fib sequence? a, b = b, a + b Start with a routine to get the number(s) …

Member Avatar for srk619
0
146
Member Avatar for BlueNN

Not tested but should be close. In these types of programs, you want to set a variable to assume that there are errors and unset it only when all conditions are met.[code]errors = True while errors: age = input('How old are you today? ') try: age_int = int(age) if (age_int …

Member Avatar for adam1122
0
114
Member Avatar for tlinux

I have a symlink from /usr/bin/python to python2.5 as the default. If I want to use 2.6 or 3.x I simply use the shebang #!/usr/bin/python3.0 They install into different library directories, so multiple versions isn't problem.

Member Avatar for scru
1
387
Member Avatar for pythonator
Member Avatar for Malestryx

This "is" operator is meant to be used to test for the same object, not equality. Try this on your computer a=257 print a is 257 <prints "False"> So it can give you unexpected results. You want to use: [code] a = True while a : a = False ## …

Member Avatar for woooee
0
91
Member Avatar for originalremix

This line doesn't make any sense.[code]x = "a" or "b" or "c" or "d" or "e" or "f" or "g" or "h" or "i" or "j" or "k" or "l" or "m" or "o" or "n" or "q" or "r" or "s" or "t" or "u" or "v" or "w" …

Member Avatar for woooee
0
172
Member Avatar for Oakie

You would use a dictionary to convert.[code]convert_dic = {"I":1, "V":5, "X":10, "L": 50, "C ":100, "D": 500, "M": 1000 }[/code]Also, this line should be "equal to or greater than". if romaninput[0] > romaninput[1]: Better yet, use a for loop to iterate through all of the roman numerals. Sorry if this …

Member Avatar for Oakie
0
1K
Member Avatar for Malestryx

Depending on the version of Python you are using, this may or may not return a string hours = input("How many hours did they work?: ") If it is a string and not a float print type(hours), the function should return float(hours) Hopefully, it is obvious why you want to …

Member Avatar for woooee
0
106
Member Avatar for s_jmp
Member Avatar for zain kazmi
0
89
Member Avatar for LateNiteTippin

You are over-thinking this[CODE]list_n = [[3, 2], [5, 1], [4, 7]] print "Before", list_n for j in range(0, len(list_n)): row = list_n[j] row.append(0) ## can also use just list_n[j].append(0) print "After ", list_n [/CODE]

Member Avatar for LateNiteTippin
0
2K
Member Avatar for pythonnewbie1

Start with just this part and post the code here.[QUOTE]Using a loop, allow the user to input as many student names as they like[/QUOTE]

Member Avatar for jlm699
0
227
Member Avatar for tillaart36

You can specificy a different delimiter. The code below is from the official docs. But for an either/or situation, if you don't want to write your own routine, the easiest is probably reading each file, replacing a semicolon with a comma if found, and writing to a new file. Then …

Member Avatar for tillaart36
0
2K
Member Avatar for harrykokil

Check Pmw and Tix. Here is an example with Pmw [url]http://www.java2s.com/Code/Python/GUI-Pmw/GaugemadefromPmwMegaWidget.htm[/url]

Member Avatar for woooee
0
76
Member Avatar for Coolprogram

I think you just want a simple menu program[CODE]def func_a(): print " hello world import" def func_b(): print " hfile import" ##------------------------------------------------------------------- menu_d = { "awesome1":'func_a()', "/help":'func_b()'} choice = "" while choice not in menu_d: choice = raw_input("type /help to continue or the password:\n ") if choice in menu_d: eval(menu_d[choice]) …

Member Avatar for woooee
0
143
Member Avatar for besktrap

This online book has a good explanation of arguments [url]http://en.wikibooks.org/wiki/Python_Programming/Functions[/url] After that, the best way to learn is to try a few things yourself, print the results, and see what is happening.

Member Avatar for besktrap
0
120
Member Avatar for jessica2009

Also note that in the following code you convert to upper case after testing for an upper case letter. You want to convert to upper() once only directly after the input. [CODE] if userit == A: userit = userit.upper() print ("\n Thats good. I like it too ") ,userit ,[/CODE]This …

Member Avatar for woooee
0
139
Member Avatar for DisembodiedLoaf

Also, add the code for how you call these functions if you post again. Some errors are simply caused by a function not being called with parameters, etc. and since you don't print or return from "sides" there is a potential problem there as well. Edit: I see that you …

Member Avatar for shadwickman
0
181
Member Avatar for lilkid

The problem may be that you are using the reserved word "file" and perhaps overloading it. file and open are basically the same for Python. So use something other than "file", check the contents of the output file with a text/word processor to see that it is really there 3 …

Member Avatar for lilkid
0
128
Member Avatar for Darkangelchick

There are two separate parts of course. Start with the logic 1. How are you going to identify the individual squares, by row and column, or will each square have a unique number. And how will you test to see that the square is not already occupied, which will be …

Member Avatar for woooee
0
650

The End.