2,190 Posted Topics
Re: 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 = [] … | |
Re: 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 | |
Re: 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 … | |
Re: 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 … | |
Re: "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'], … | |
Re: What does that mean and what do you want the program to do? | |
Re: 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. | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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: … | |
Re: 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. | |
Re: >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, … | |
Re: 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. | |
Re: 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 … | |
| |
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 … | |
Re: 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 … | |
Re: 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) | |
Re: 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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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] | |
Re: 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 | |
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 … | |
Re: 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 … | |
Re: Anything that involves a dozen. Mmmmm doughnuts. | |
Re: See [one of the Tkinter docs](http://epydoc.sourceforge.net/stdlib/Tkinter.Place-class.html) on the web and take a look at forget. | |
Re: Typically that means that a return statement is indented incorrectly. Check all of your return statements. | |
Re: > 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 … | |
Re: 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. | |
Re: 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) | |
Re: 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") | |
Re: >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() | |
Re: Do you know about Python's built in sort? Try print this_list.sort() Bubble sorts are pretty straight forward btw. | |
Re: 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 … | |
Re: Please read [the announcement here](http://www.daniweb.com/software-development/computer-science/threads/573) | |
Re: 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 … | |
Re: 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" | |
Re: 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 … | |
Re: 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 … | |
Re: 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) | |
Re: 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. | |
Re: > 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, … |
The End.