2,190 Posted Topics

Member Avatar for nytman

The easiest to understand is to [Use a function](http://www.tutorialspoint.com/python/python_functions.htm) def get_one_salary(ctr): while True: ##infinite loop salary=raw_input("enter the salary #%d: " % (ctr+1)) try: salary = float(salary) return salary except ValueError: print "could you please enter the correct salary? " n = int(raw_input("enter the number of employee: ")) salary = [] …

Member Avatar for nytman
0
1K
Member Avatar for otto531

May already be answered, Duplicate (cross-posted) at http://bytes.com/topic/python/answers/947596-how-can-i-find-top-words-frequencies-combined-files#post3743844 and http://forums.devshed.com/python-programming-11/return-common-words-in-two-files-941286.html

Member Avatar for bumsfeld
0
312
Member Avatar for sugarzzzz

You don't have a [0, 15] in the example you posted, you have [0, 0] through [3, 3]. If you have a board = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] --> 16 zeros then you can access the 15th. Show …

Member Avatar for woooee
0
123
Member Avatar for aVar++

That would be just a simple 1. compare the first number with the remaining (2 in this case) 2. swap the first and second number and do again You would continue swapping if there were more digits. You have not included enough actual code to really comment on so it …

Member Avatar for Ene Uran
0
289
Member Avatar for jeremywduncan

"Better" is in the eye of the beholder. The first rule is that the program does what it is supposed to. def in_order(t): for ctr in range(1, len(t)): if t[ctr-1] > t[ctr]: return False return True for t in ([1,2,2], ['b','a'], [3, 1, 5, 2, 4], ['d', 'a', 'c', 'b'], …

Member Avatar for jeremywduncan
0
830
Member Avatar for Fernando_1
Member Avatar for dp121307

The else statement only executes if the name is not correct, regardless of what the password is (name=correct & password=incorrect = nothing is printed). Note also that A['user'] and A[password'] will only contain the last value from the while loop, so you should print the dictionary to verify this.

Member Avatar for woooee
0
2K
Member Avatar for Greyhelm

If finds "didn't" in the following test. Also, you do not strip the newline character(s) after reading the files, and because you use "in" instead of creating a dictionary or set of individual words and comparing word with word; the word "and" will be found, i.e. is in, when compared …

Member Avatar for Greyhelm
0
418
Member Avatar for longtomjr

Lists are mutable, which means they can be used without global. The problem is possibly in the code you use to update the list; it truncates the list also. Run the code example below. You are asking questions that are in most tutorials so you should start with a tutorial …

Member Avatar for woooee
0
225
Member Avatar for Niner710

It appears that bayFails is a class instance ><class 'pandas.core.series.Series'> and so can not be converted to a list. You will have to access the data within the class. Since we have no idea were bayFails comes from, the only advice would be to read the Pandas docs since extracting …

Member Avatar for dashing.adamhughes
0
1K
Member Avatar for clouds_n_things

Do you want to search for a file name ending, "data" i.e. list of files, if not, state what you do want the program to do?? Now you do the same search [the result from input()] for each file name returned from os.listdir command_line = input('Enter the game you would …

Member Avatar for clouds_n_things
0
169
Member Avatar for aVar++

Use a while loop to generate random numbers until a valid number occurs: - Ships can't overlap --> keep track of the occupied squares in a list - Ships must be within the gamegrid --> you can supply a range for rows and a range for columns - Ships must …

Member Avatar for woooee
0
464
Member Avatar for pxalpine

For starters, print the result/"word" for for word in f: Also, "data" has not been declared if i in data: Read cities.txt and place the cities in a list or dictionary. Print this to make sure there is no white-space, etc. Then search for each of the cities in each …

Member Avatar for pxalpine
0
146
Member Avatar for nitin1

A rather long, but funny transcript where a "hacker/cracker" tries to crack someone else's computer. The catch is that the inept cracker is told that the IP address of the other computer is 127.0.0.1 [http://www.frihost.com/forums/vt-51466.html] "This is a transcript of the worlds dummest hacker on an IRC channel. The comments …

Member Avatar for <M/>
0
204
Member Avatar for flebber

I can't tell what your code looks like because it is not indented. doubler is now f(2) = return g so that is removed and the value from doubler(5) gets assigned to y that is why you get the x*y value and not "function g at blah blah" which is …

Member Avatar for flebber
0
149
Member Avatar for Lardmeister

2012 is one of the times for the beginning of the Aquarian age. Pisces (the fish) probably began about 100-200 BC (when Jesus actually lived and ushered in the age-maybe) and so is associated with the Christian religion. In the Bible you find references to the age of Taurus, especially …

Member Avatar for sneekula
2
2K
Member Avatar for rev_ollie

You have to capture the return from split() and iterate over each one. Using split eliminates the split characters so you can prepend them back or adjust the slice numbers by -2 as I have done below. test_data=\ "7e001090007d33a200408b2e0c2db70100160057637e001090007d33a2004089e04a569d010016003885" if test_data[0:2] == '7e': data_split=test_data.split('7e') print data_split for Data_in in data_split: …

Member Avatar for rev_ollie
0
4K
Member Avatar for clouds_n_things

Take a look at the first code example [Click Here](http://effbot.org/tkinterbook/button.htm) especially how text is assigned so it appears on the button.

Member Avatar for clouds_n_things
0
3K
Member Avatar for pmec

>00:02:500 # should be 00:02:30 A half a second is 500 milliseconds so 2:500 (== 2.5) is correct > 00:03:0 # should be 00:03:30 We don't know what code you are using so how do you expect someone to help? Take vegaseat's suggestion and print the variables total_seconds, millisec, minutes, …

Member Avatar for ZZucker
0
5K
Member Avatar for chophouse

cur.execute("""INSERT INTO TableX (itemID, sortID) VALUES (%s, %s)""", [plist[sid], lastQ[0] ] ) What type is plist[sid]? If it is a string you now have to cast it to a byte in Python3.x (encode it), possibly the cause is something in Python3.3.

Member Avatar for chophouse
0
631
Member Avatar for clouds_n_things

The "in" operater is used to look up a key in a dictionary --> dictionary tutorial http://www.greenteapress.com/thinkpython/html/thinkpython012.html Note rrashkin's advice above and store each item in a string or as an element of a sub-list so you can access them individually as (s)he has done. You should not post real …

Member Avatar for clouds_n_things
0
191
Member Avatar for smitmail22
Member Avatar for woooee

Hi Guys, Please be gentle with me as im a complete n00b. My favorite language is actually Java which im learning at Uni at the moment. However to throw a spanner in the works they have switched us over to Python, as well as learning Java. My mind has been …

Member Avatar for Lardmeister
1
173
Member Avatar for mgunia

You should use a dictionary to store the e-mails in a dictionary if it is not already there. If it is there, then it is a duplicate. I would suggest that you store the original record and the duplicate because they may be different and you would want to keep …

Member Avatar for vegaseat
0
9K
Member Avatar for pbnoj

And you can do this more compactly BR1 = [] for ctr in range(2, 8): BR1.append(Resistance[ctr] ## replaces BR1 = [] b1 = Resistance[2] b2 = Resistance[3] b3 = Resistance[4] b4 = Resistance[5] b5 = Resistance[6] b6 = Resistance[7] BR1.append(b1) BR1.append(b2) BR1.append(b3) BR1.append(b4) BR1.append(b5) BR1.append(b6)

Member Avatar for woooee
0
211
Member Avatar for SumTingWong59

That is because "! =" does not equal "!=" (original code copied for reference). #------------------------------------------------------------------------------- # Name: module1 # Purpose: # # Author: User # # Created: 18/12/2012 # Copyright: (c) User 2012 # Licence: <your licence> #------------------------------------------------------------------------------- #tictactoe board import random board = [0,1,2, 3,4,5, 6,7,8] def game(): print …

Member Avatar for woooee
0
89
Member Avatar for happymadman

You define text_list to point to the same block of memory as final. final = text_list If you want want a copy, use [copy or deepcopy](http://docs.python.org/2/library/copy.html) In line 107 you append final to decode_list multiple times. Break the program down into small functions that you can test individually, as fixing …

Member Avatar for woooee
0
136
Member Avatar for chris99

Your original problem was a missing closing parens in this statement self.button.append(Button(frame, text=str(i), width=5, command=lambda i=i:self.numberPressed(i)) In the future, remember to check the statement before the one indicated for syntax errors as it happens a lot.

Member Avatar for woooee
0
133
Member Avatar for AutoPython

Does everyone know about Doug Hellmann's Python Module Of The Week. A good source for basic learning. [url]http://www.doughellmann.com/PyMOTW/threading/index.html#module-threading[/url] [url]http://www.doughellmann.com/PyMOTW/about.html[/url]

Member Avatar for nytman
3
1K
Member Avatar for padton

For starters, you can use a loop import os for path in [["x"], ["x", "y"], ["x", "y", "z"]]: pathname = "pathname" for next_path in path: pathname = os.path.join(pathname, next_path) print pathname

Member Avatar for TrustyTony
0
231
Member Avatar for woooee

The problem is explained by the comments in the code. It is a fundamental question about the method call...every time I try text_box_name.tk_textBackspace() I get the TclError message. That's why I asked the question without the code... # When user enters a search word in the +search_box' text widget and …

Member Avatar for woooee
0
287
Member Avatar for aVar++

Take check() out from under NAC()--[capture the return from a function](http://www.tutorialspoint.com/python/python_functions.htm) def check(player): if player == Grid[0][0] == Grid[0][1] == Grid[0][2]: print("%s wins!", (player)) return True Please read the [Python Style Guide](http://www.python.org/dev/peps/pep-0008/) to make your code readable. Functions and variable names are lower case with underscores. You have redundant code …

Member Avatar for aVar++
0
290
Member Avatar for nitin1
Member Avatar for satsujin

See [one of the Tkinter docs](http://epydoc.sourceforge.net/stdlib/Tkinter.Place-class.html) on the web and take a look at forget.

Member Avatar for satsujin
0
2K
Member Avatar for jlh070945

Typically that means that a return statement is indented incorrectly. Check all of your return statements.

Member Avatar for woooee
0
147
Member Avatar for WhiteTulip

> but I'm not really sure where to go next That is too vague to understand what you mean. Draw the whole thing out on paper, breaking it into steps. Also, add some print statements to help with debugging. You are using for i in letter(): for example and the …

Member Avatar for woooee
0
312
Member Avatar for satsujin

Instead of calling the same class instance every time, you are creating a new class instance self.canvas.bind("<Button1>", win2(self.canvas)) As stated above, you should create one instance of each class in __init__() and use those.

Member Avatar for satsujin
0
190
Member Avatar for lewashby

Set third to 0 (False) and see how that affects things. An "and" is 2 nested if statements: if first > second: if third: See [5.1. Truth Value Testing](http://docs.python.org/2/library/stdtypes.html)

Member Avatar for woooee
0
234
Member Avatar for tizzqman

Try this for a hint alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "XPMGTDHLYONZBWEARKJUFSCIQV" for ctr in range(len(alpha)): print alpha[ctr], key[ctr] print print alpha.find("F")

Member Avatar for woooee
0
110
Member Avatar for slasel

>bh1=Radiobutton(tophelicase,text='1',variable=position,value=1,bg="green",command=tophelicase.destroy).pack() Print bh1 to see what it contains and you should see that there is no reason to store the return from pack(), i.e. just use Radiobutton(tophelicase,text='1',variable=position,value=1,bg="green", command=fhelicase).pack()

Member Avatar for slasel
0
286
Member Avatar for pinbustersrule

Do you know about Python's built in sort? Try print this_list.sort() Bubble sorts are pretty straight forward btw.

Member Avatar for noonecares
0
889
Member Avatar for ailen.samson

Add a print statement after this line to see what you are doing for item in enumerate(a): for item1 in enumerate(b) print "checking" item, item1 You want to subtract 2 items in the list, convert the difference to a positive number, and store the smallest number found, and if you …

Member Avatar for woooee
0
904
Member Avatar for Carlsn

Please read [the announcement here](http://www.daniweb.com/software-development/computer-science/threads/573)

Member Avatar for woooee
0
657
Member Avatar for tizzqman

Check the line indentations up to and including that point. Also, you only want one input function instead of one in each function. You then test for the input and call the appropriate function. You can write one function to convert anything to one common measure, say millimeters for example …

Member Avatar for sneekula
0
232
Member Avatar for biscayne

You should first test that what you want is there. for cell in row: tmp = ('%VAR_' + headerRow[i] + '%') if tmp in line: line = line.replace(tmp, cell) # string.replace(old, new) print "replaced line =", line else: print tmp, "not found"

Member Avatar for biscayne
0
196
Member Avatar for bintony.ma_1

Also, you read the file twice. If you want to use your existing code, use a set or dictionary for remove_index instead of a list, as the time is taken up by sequential lookups in "if count in remove_index:". Or use instead recs_to_write=0 with open('input.txt') as infile: for line in …

Member Avatar for bintony.ma_1
0
454
Member Avatar for sym366

You could also have a list of win squares instead of checking for rows, diagonals, and columns separately. The following is pseudo-code: def check_row(self, row): control=this_column[0] for column in row ## not occupied or not all the same if column == 0 or column != control: return False return True …

Member Avatar for sym366
0
1K
Member Avatar for inaxassan

We are here to help. Post your code and any errors, and you probably have not read [this thread](http://www.daniweb.com/software-development/computer-science/threads/573)

Member Avatar for vegaseat
0
2K
Member Avatar for inaxassan

Instead of self.firstClass = firstClass self.economy = economy self.business = business which is redundant, i.e. you always have all 3, use a "class" variable that you set to "first", "economy", or "business". Also you don't have number of people or name.

Member Avatar for sneekula
-1
2K
Member Avatar for foodstamps

> Any ideas why using the input file is causing problems? No, because we have no idea what the problem is or what the output to the file actually is compared to what it should be. Add some print statements in "correct()" to see what it is doing differently. Also, …

Member Avatar for foodstamps
0
311

The End.