2,190 Posted Topics
Re: In addition to lambda, you can also use partial to pass a variable indicator to a function. Also, using pack() and grid() in the same program leads to unpredictable results. from Tkinter import* from functools import partial root=Tk() root.title("Replicate DNA yourself!") def inn(variable_passed): positions = ((10, 10), (60, 50), (110, … | |
Re: In Tkinter is would just be top.title("New Title") Or use a Label and Entry box if you have several entries and want a separate title/label for each one. Ah, you are using input, i.e. the console > x= input("blah blah blah") then you would just print a line to get … | |
Re: Start with the deck class by itself. A hand would be a list of cards dealt from the deck, so you can have as many lists/hands as you want. Something to get you started class Deck(object): def __init__(self): suits = ('C', 'S', 'H', 'D') ranks = ('A', '2', '3', '4', … | |
Re: First, use a dictionary or list of lists to hold the question and answers instead of 100 if statements. I assume you don't know about dictionaries yet so this uses a list of lists. words = [['ano', 'um'], ['ima', 'now'], ['eego', 'english']] random.shuffle(words) for this_question, this_answer in words: print (this_question) … | |
Re: What does "won't work" mean? Also, use a list that you pass to the functions instead of the global variables, a1, a2, etc. You are comparing a 3 item sub-list in done to a list that is 4 items which will never be equal. done = [['a1','a2','a3']] for testing in … | |
Re: You want to use numberAsked in the while loop instead of while len(Questions) > 0 : Also, you can use random.shuffle on the Questions list and then take them in order instead of deleting and checking for length. | |
Re: This will give you a general idea of how to start if I understand what you want. def drawRectanglePatch(x, y): win = GraphWin("Test", 300, 300) for i in range(10): for j in range(10): topLeftX = x + i * 10 ## topLeftY = y + j * 10 incr = … | |
Re: It is not obvious what you are trying to do. Nor is it obvious what GUI toolkit you are using, although it is not Tkinter or Wx which is all that I use, so we can not run your code (no imports posted). If you are trying to draw the … | |
Re: You should be using "x" and "y" passed to the function for your start position instead of the hard coded one. You can then pass a different x, y (start) to the function, assuming you are always drawing the same size triangle. In Tkinter (which doesn't look what you are … | |
Re: > def replaceVariablesWithCsvData(self, headerRow, row, lines): # lines as list of strings This function does not create a list. It creates one long string. For more precise help come up with a simple example and some test data so we can see what happens compared to what should happen. | |
Re: See the definition for append mode = "a" [Click Here](http://www.tutorialspoint.com/python/python_files_io.htm) which explains why checking is not necessary. | |
Re: You have to add the last group, and note that the counter is initialized to one since we are comparing this pixel to the next pixel, so this pixel is the first in a series. __You should also test your program with the first 2 pixels different and with the … | |
Re: Ask the user to enter a number to be guessed say between 1 and 100. The computer selects a random number in that range. If the computer guesses too low, then that number+1 becomes the lower number in the range for the next random number to choose from and so … | |
Re: > the problem is that the program creates an empty file >Not sure what to do next Test your program (note that the file is not technically "empty") def main(): inpath = input("Enter an input file: ") line = input("Enter what you want to remove: ") outpath = input("Enter an … | |
Re: The epoch is OS dependent and has nothing to do with Python. Since we don't know what OS you are using the question can not be answered except to say print gmtime(0) and see what it tells you. 28800 seconds is something like 8 hours so it may be the … | |
Re: First, read the [Homework Help](http://www.daniweb.com/software-development/computer-science/threads/573) thread. Look at one of the [Python Tutorials](http://wiki.python.org/moin/BeginnersGuide/Programmers) for assistance as this is pretty basic stuff that is included in most tutorials. Feel free to post back with specific code problems for help. | |
Re: This doesn't have anything to do with Python. See if the task manager gives a create time or does something simple, like number the processes sequentially so you can tell which is which. Perhaps someone else will know something more about Visual Basic and the Task Manager. | |
Re: You should first test the calc_average function. `print calc_average(75, 75, 75, 60, 90)` Also you might want to convert to a float which depends on the version of Python you are using. | |
Re: First read http://www.daniweb.com/software-development/computer-science/threads/573/we-only-give-homework-help-to-those-who-show-effort then see if it is the same homework problem as http://www.daniweb.com/software-development/python/threads/439588/python-data-extraction-help or http://www.daniweb.com/software-development/python/threads/439504/converting-a-list-to-a-a-string-of-integers | |
Re: Check the permissions first. Does the user (you) have permission to open the file? | |
Re: This thread appears to use the same data, and so is probably the same homework problem as http://www.daniweb.com/software-development/python/threads/439504/converting-a-list-to-a-a-string-of-integers We should perhaps combine them into one. > ['ID ', ' Last ', ' First', ' Lecture', ' Tutorial', ' A1', ' A2', ' A3', ' A4', ' A5\n'] In the case … | |
Re: You are perhaps over thinking this with all of the complicated print statements. You now want a second function with num_dots, num_spaces, and num_stars, and print and then add/subtract from each field accordingly. def top_down(my_len, spaces): num_dots = 1 for ctr in range(my_len): print ' '*spaces + '.'*num_dots num_dots += … | |
Re: Automatically executing in the current directory is considered dangerous as an attacker could add their own bash for example in the current directory. It would be executed if the current directory is searched first and could do anything the programmer wished. You can add PATH=$PATH:. and export it to .bashrc … | |
Re: What happens when "variables != '2'" ? ## Three variables print "HOW MANY VARIABLES WOULD YOU LIKE?" for ctr in range(3): print ctr+1 names_list=["FIRST", "SECOND", "THIRD"] MainLoop = 1 while MainLoop == 1: name_of_variables=[] variables = raw_input ("Enter Variables ") for ctr in range(int(variables)): name = raw_input ("NAME YOUR %s … | |
Re: > I also want it to display a message when there is no vowel entered Check the length of a set intersection test_sentence="The quick brown fox" v = set(['a', 'e', 'i', 'o', 'u']) print v.intersection(set(test_sentence)) or set some indicator msg = input("Enter a sentence: ") #v = set(['a', 'e', 'i', … | |
Re: One of the many [Python functions tutorial](http://www.tutorialspoint.com/python/python_functions.htm). | |
Re: Use [readlines()](http://www.peterbe.com/plog/blogitem-040312-1) to get a list of the records. You can then [access a record in the list](http://www.tutorialspoint.com/python/python_lists.htm) by offset value just like any other list. | |
Re: You first split the sentence into words, then print accordingly. I will leave dealing with punctuation to you. A simplified example: test_input="help I don't know how to do these tables." test_list=test_input.split() ctr=0 for outer in range(3): for inner in range(3): print test_list[ctr], ctr += 1 print | |
Re: What is the while loop supposed to do?? Right now it just prints. Note that while sum == point: will never be True because you are comparing an integer and a tuple. | |
Re: > but I have continuously been getting an error saying that a str object cannot be interpreted as an integer We have no idea what or where this may be. Post the complete error message which includes the offending line and also state which version of Python you are using … | |
Re: Note how the class Board is declared inheriting Human. Also, the __init__ in Board overrides the __init__ in Human so you have to explicitly call it with "super" in new style classes, otherwise the variables in Human's __init__ are not declared. class Board(Human): def __init__(self): super(Board,self).__init__() self.board = [] self.mark … | |
Re: a[0:9:-1] #why is this not equivilent to a[::-1] start at a[0], (then -1 = a[-1] which doesn't exist), and go in reverse order until the number is less than 9, which zero is. You want, a[end:start-1:-1], but why even try to reinvent the wheel that is already working. | |
Re: This statement is part of your problem self.master.bind('<Configure>', self.resize) Also, you misspelled "tag". Other than that, moving the circle works fine for me. Since you always print the text in the same place and test the same coordinates, you will always get the same results. You have to keep track … | |
Re: You are choosing from the dictionary's values not the keys, and then using the values instead of a key for lookup while wordlimiter < 10: ## returns values linked to first_word next_word = random.choice(worddict[first_word]) you possibly want next_word = random.choice(worddict.keys()) ## or test for membership next_word="" while next_word not in … | |
Re: Please read the sticky threads [Homework Help](http://www.daniweb.com/software-development/computer-science/threads/573) If you have no idea then there is not much that can be done with this problem. I would suggest that you start with something easier where you do have some idea of what to do. | |
Re: And you first want to check that the index is in the dictionary to avoid an error message. dictionary={a:1, b:2, c:3 ...etc} lookup=[a, a, b, c, c ... etc] results = [dictionary[key] for key in lookup if key in dictionary] | |
Re: Take a look at chapter 19 in the official pygtk tutorial. | |
Re: When will the variable "a" be found in the following code? a = '' for word in range(len(board)): ## do you really want to look for a='' if a in make_str_from_row(board, word): return True > I have a function that checks if a str is part of a list of … | |
Re: You did not include the complete error message so we have no idea which variable gives the error. Dagger should possibly be a data attribute/instance variable instead of a class variable http://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch22s06.html http://www.diveintopython.net/object_oriented_framework/userdict.html#fileinfo.userdict.init.example | |
Re: Please read the [Homework Help](http://www.daniweb.com/software-development/computer-science/threads/573) sticky. | |
Re: There is no need to reverse the list twice as you can use -1 in a for loop and start at the back end. Other than that, you have to look at all elements from the back of the list to the first non-0xFFFF however you do it. | |
Re: To get you started: for ctr in range(8): print 2**ctr, for ctr in range(6, -1, -1): print 2**ctr, print for ctr in range(2): print 2**ctr, for ctr in range(0, -1, -1): print 2**ctr, print for ctr in range(1): print 2**ctr, for ctr in range(-1, -1, -1): print 2**ctr, print To … | |
Re: On Linux, you can add a path to the PYTHONPATH variable in ~/.bashrc. Add this line export PYTHONPATH=${PYTHONPATH}:/new/path:/another/path:/colon/separates The next time you boot, the PYTHONPATH will reflect the changes. | |
Re: You should send the time value entered to the class, so this statement should be in a function that is called when the "Convert" button is pressed conv = Converter(5) and should send the value from the Entry instead of "5" (links to [using get to read an entry](http://effbot.org/tkinterbook/entry.htm) and … | |
Re: Instead of complicated and+or statements without parens so no one knows what the computer is actually doing elif row1.value == row2.value == row3.value and row4.value == row5.value or row3.value == row4.value == row5.value and row1.value == row2.value: use --> for unique value in list of rolls/dice, count each unique value … | |
Re: What that post means is, you execute the return from rollin (which is 'None') because of the parens. It should be rolldice = Tkinter.Button(row2, command=rollin, text = "Roll") See [Click Here](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) for info on bindings and callbacks. Also, you do not include the parens when you call dx.roll within rollin() … | |
Re: Start by printing x, y, and z. And print the return. These are always good places to start. def calcdist(data): for p in data: x = p[:1] y = p[:2] z = p[:3] print "x, y, and z =", x, y, z for i in range(len(data)): dist = sqrt((x[i]-x[i+1])^2 + … | |
Re: It is very easy. Just lay it out in a list and print the list. A simplified example. to_draw = [[" ", "O"], [" ", "|"], ["\\", " ", "/"], [" ", "|"], [" ", "|"], ["/", " ", "\\"]] for each_list in to_draw: print "".join(each_list) |
The End.