2,190 Posted Topics

Member Avatar for Taiki

What do you want to do in Tkinter other than the menu, and what do you want the entire program to do? A couple of comments: [code] def __init__(self,denom,value): self.Denomination = "CENTS" self.Value = 0 ## if the value is not 25 or 50 then self.Value remains at zero ## …

Member Avatar for Taiki
0
2K
Member Avatar for mattgwilson
Member Avatar for mattgwilson
0
157
Member Avatar for carmstr4

And what happens when they guess "books" and it is "bones". You have to eliminate a letter that is found or it will "find" two o's when there is only one. Since we don't know what kind of containers realWord and guess are, I am using a list since they …

Member Avatar for carmstr4
0
2K
Member Avatar for pelin

[code]def create_deck(): deck = [] for i in range(10): for color in ['blue','green','red','yellow']: if i == 0: card = StandardCards(color,i) deck.append(card) else: card = StandardCards(color,i) deck.append(card) card = StandardCards(color,i) deck.append(card) [/code]You create 1 + 2*9 cards for each of the colors=76 cards, plus the wild cards.

Member Avatar for pelin
0
6K
Member Avatar for mkbear

You should not use "i", "l", or "O" for variable names as they can look like digits as well as other letters. This code is a good example of why. You will have to discover the problem yourself (the problem may be caused by being too lazy to key in …

Member Avatar for inuasha
0
222
Member Avatar for mkmk123

That is not list append, but a [url=http://www.java2s.com/Code/Python/List/Listinsertix.htm]list insert[/url]. Another way to do it to create a new, third list by appending list 1 until "+++++++" is found, then append list 2, then append the rest of list 1.

Member Avatar for mkmk123
0
274
Member Avatar for mwjones

[quote]but when the chunk is inserted, each item gets a "\n"[/quote]Python does not write a "\n" to a file as it does with a print statement. If there is a "\n" it must be in the string, so print the string so you know what is being added. Also, ImageMagick …

Member Avatar for woooee
0
229
Member Avatar for theraggamuffin

Use a function to draw the rectangles. Within a loop, send the function the parameters for the smaller rectangle, then send the parameters for the 4 larger rectangles, and finally a smaller rectangle. It will draw a row for every iteration in the loop.

Member Avatar for theraggamuffin
0
288
Member Avatar for bellarc

[quote]File "par.py", line 6 line = line.replace(" ^[/quote]Note the mark at the beginning of the line, which usually means the problem is the previous line. [code]## test with this first for line in fileinput.FileInput(files="./test.txt"): print line # ## iterates over the lines of all files listed in sys.argv[1:] for line …

Member Avatar for woooee
0
333
Member Avatar for hovestar

The main problem is that you don't pass board to the function, update it, and then return the new board. Consider using a list instead of a string as it makes things much easier. Also use a loop to get the input instead of 5 separate sets of statements. [code]import …

Member Avatar for woooee
0
204
Member Avatar for ppotter3

lpr is the print spooler on Linux so you should be able to do something similar to [code]import subprocess subprocess.call("lpr "+filename.txt, shell=True) [/code]"man lpr" will give you all of the print options that lpr supports.

Member Avatar for ppotter3
0
339
Member Avatar for the_azn_invasio

For starters, this does not make sense [code] if line.count('<') == 0: line [/code]Here, you are splitting a list which should yield an error message that says you can only split strings, not lists. [code] else: frag1 = line.split('<')[1] try: frag2= frag1.split('>') [/code]And why are you implementing all of the …

Member Avatar for woooee
0
299
Member Avatar for AdampskiB

Note how the variables increase by one in this code (but in your example output they decrease??) [code] for a in range(n, 0, -1): print(a, end="\n") for i in range(n+1, 0+1, -1): print(i, end="\n") for j in range(n+2, 0+2, -1): print(j, end="\n") for f in range(n+3, 0+3, -1): print(f, end="\n") …

Member Avatar for techie1991
0
167
Member Avatar for happygeek

[quote]All he needed was $1,500.00 USD for the plain ticket.[/quote]It was smart to ask her for the money for a plain ticket instead of the more expensive elaborate ticket.

Member Avatar for Ancient Dragon
0
525
Member Avatar for next_tech

"grid is not an instance variable, but a class variable. That means that it is common to all class instances. See the example below. I think you want to use an instance variable. [code]class Board: SIZE = 3 grid = [] def __init__(self, var): self.grid.append([var]) print self.grid b = Board("b") …

Member Avatar for woooee
0
114
Member Avatar for vlady

If you want to save more than one grade per student, use a dictionary of lists. [code]marks = {"alice" : ["A+", "B-"], "smith" : ["A", "A"], "daemon" : ["B+", "B"], "lily" : ["B", "C"] } [/code]

Member Avatar for vlady
0
130
Member Avatar for s00pahFr0g

Assuming self.cards is a list: [code]cards = range(1, 53) print cards cards_shuffled = cards[26:] + cards[:26] print cards_shuffled # # or to modify your code (this assumes cards are numbered 1-52, not 0-51) cut_deck = [] for loop in range(26, 53): ## 53, __not__ 52 = 1-52 cut_deck.append(self.__cards[loop]) for loop …

Member Avatar for TrustyTony
0
312
Member Avatar for Flames91

A hint regarding accessing the dictionary. [code]class Polynomial: def __init__(self, *termpairs): self.termdict = dict(termpairs) print (self.termdict) def print_result(self, key): print "%dx^%d" % (key, self.termdict[key]) if __name__ == '__main__': d1 = Polynomial((2,3), (4,5), (8,9)) ## extract and sort keys to process in numerical order keys=d1.termdict.keys() keys.sort() for key in keys: d1.print_result(key) …

Member Avatar for TrustyTony
0
517
Member Avatar for arindam31

There are [url=http://www.daniweb.com/software-development/python/threads/162038]examples on Daniweb[/url] that you can use as well as on the web. This is a very simple and common question. [quote]I am not using 'textctrl' as i will have to create a seperate frame , add buttons and add functionality to that again which is again tedious.[/quote]Laziness …

Member Avatar for arindam31
0
235
Member Avatar for obito

It's not obvious what you want to do. If you want to capitalize the first word of the sentence: [code]test_recs = "The quick brown fox jumped over the lazy dog. test sentence number two." new_rec_list=[] for sentence in test_recs.split(". "): if len(sentence): new_sentence = sentence.strip().capitalize() new_rec_list.append(new_sentence) print ". ".join(new_rec_list) [/code]

Member Avatar for TrustyTony
0
112
Member Avatar for MakingMoney

If you want to access or print all the numbers, append them to a list test_list = [1, 2] ## Fibs can be started with any 2 numbers test_list.append( test_list[-1]+test_list[-2] ) print test_list

Member Avatar for TrustyTony
0
2K
Member Avatar for Jetster3220

[QUOTE=Jetster3220;1694474]still having problems with the program... Won't go past question three and checking answers section wrong[/QUOTE] Dont' know what "Won't go past guestion three" means. On input, on writing, on checking answers? And have you already created the file "few_questions.txt" with the questions in it (that could be the cause …

Member Avatar for woooee
0
320
Member Avatar for bigredaltoid

You can do it this way, but it would be better to use a for() loop: [code]ctr = 0 line1 = myFile.readline() while line1: myOut.write(line1.strip("\n")) ## 4 records without end-of-line ctr += 1 if ctr > 3: ## 4 records written myOut.write("\n") ctr = 0 line1 = myFile.readline() [/code]

Member Avatar for bigredaltoid
0
166
Member Avatar for sainitin

The easiest to understand is to store the previous record, and find the number for the record previous to the ">" record. [code]seq=""">s1\n MPPRRSIVEVKVLDVQKRRVPNKHYVYIIRVTWSSGATEAIYRRYSKFFDLQMQMLDKFP MEGGQKDPKQRIIPFLPGKILFRRSHIRDVAVKRLIPIDEYCKALIQLPPYISQCDEVLQ FFETRPEDLNPPKEEHIGKKKSGNDPTSVDPMVLEQYVVVADYQKQESSEISLSVGQVVD\n >s2\n MAEVRKFTKRLSKPGTAAELRQSVSEAVRGSVVLEKAKLVEPLDYENVITQRKTQIYSDP LRDLLMFPMEDISISVIGRQRRTVQSTVPEDAEKRAQSLFVKECIKTYSTDWHVVNYKYE DFSGDFRMLPCKSLRPEKIPNHVFEIDEDCEKDEDSSSLCSQKGGV\n""" split_seq = seq.split("\n") name = "" pattern = 0 previous_rec = "" for line in split_seq: line = line.strip() if …

Member Avatar for woooee
0
193
Member Avatar for effBlam

One way is to use a StringVar. When you change it's contents, the change shows up on the GUI. And you should [url=http://effbot.org/tkinterbook/button.htm]read up on buttons[/url] as yours don't do anything when clicked. [code]from Tkinter import * from tkFileDialog import * class Game(): def __init__(self,root): self.root = root self.var1 = …

Member Avatar for effBlam
0
180
Member Avatar for python12345

That's because there is an infinite loop in the program. Because "n" does not change, the while loop never exits. We have no way of knowing how you want to change the number if it is divisible by 2, or how you want to change it if it is not. …

Member Avatar for Rick345
0
12K
Member Avatar for just_starting

Open and read the file once into a list at the start of the program. If there are adds, simply add them to the list. Write the file once at the end of the program. I am guessing that each record in the file will contain the student's name and …

Member Avatar for just_starting
0
189
Member Avatar for samymcdonnell

I like this explanation of the parts of a function [url]http://www.tutorialspoint.com/python/python_functions.htm[/url]. Tutorials are there for a reason, i.e they can be written once and read many times by many people. Start a list of good tutorials so you don't have to post to a forum with questions about very basic …

Member Avatar for woooee
0
512
Member Avatar for Joey7

I would suggest that you print word_freq. You possibly want to use setdefault instead of .get although there is no description of what you want this part of the code to do so there is no way to tell for sure. [code] for word in word_list: word_freq.setdefault(word.lower(),0) word_freq[word.lower()] += 1 …

Member Avatar for woooee
0
155
Member Avatar for ThisBoy

Use a list of lists [code]card_list = [ [], [], [], [], [], [], [] ] x = 0 while x < 7: ## number of cards to be dealt to each hand ## each for() loop deals one card to each of the hands in card_list for ctr in …

Member Avatar for woooee
0
124
Member Avatar for Emred_Skye

Adding print statements will tell you what is going on. [code]for line in in_file: print "line =", line number = line.split() print "number =". number for col in number[0]: print "comparing", col, number[3] if col == number[3]: print number[0], number[1], number[2], number[4] [/code]

Member Avatar for Gribouillis
0
283
Member Avatar for pelin

Put the objects in a list or dictionary and draw the appropriate object each time there is a miss. [code]win = GraphWin("Test", 500, 650) start_x = 200 object_dict = {} obj = Circle(Point(start_x,200),50) object_dict[0] = obj ctr = 1 for ln in ((0, 150, 0, 100), (0, 100, -100, 100), …

Member Avatar for woooee
0
151
Member Avatar for sys73r

[code] content = row[0] + row[4] + row[5] + row[11] + row[12] + row[13] + row[16] + row[17] + row[22] csv_out.writerow( content )[/code]The above uses 9 fields. [quote]# I want it to save the file in csv format as: 1,2,yhnujmik,2121212121[/quote]This has 4 fields. [quote]however the code is generating this: 1,2,y,h,n,u,j,m,i,k,2,1,2,1,2,1,2,1,2,1[/quote]This …

Member Avatar for sys73r
0
200
Member Avatar for A.D.M.I.N

[QUOTE=A.D.M.I.N;1690514]I mean how could I do this?[/QUOTE] Pass a parameter to the function, and return the desired result as many times as you want. You can start at "A first program" [url=http://www.pasteur.fr/formation/infobio/python/ch01.html#d0e115]here[/url] and also [url=http://www.pasteur.fr/formation/infobio/python/ch08.html]here[/url] and [url=http://www.pasteur.fr/formation/infobio/python/ch11s02.html]here[/url]. No on wants to do this for you as it is simple and …

Member Avatar for woooee
0
302
Member Avatar for rickymohanty
Member Avatar for unmatchedz

Post the formula that you would like to use for solving the problem. The most common method is layer by layer. Also, post the code here if you want people who don't have, or want to deal with MS Windows archiver to respond.

Member Avatar for unmatchedz
0
212
Member Avatar for BWall

I prefer using a list. [code]word1 = "hangman" blank_word = [] for c in word1: blank_word.append('_') print blank_word for guess in ["a", "b", "n"]: print("testing", guess) for ctr in range(len(word1)): if guess == word1[ctr]: blank_word[ctr]=guess print(" ".join(blank_word)) [/code]

Member Avatar for woooee
0
181
Member Avatar for eikonal

I think you want something like this, but post back if I do not understand [code]## store the recs in a set to make look up fast ## this assumes no two records are the same recs_list = open('event_from_picks', 'r').readlines() event_set = set(recs_list) for key, list_of_numbers in event_dict.items(): if key …

Member Avatar for woooee
0
369
Member Avatar for Tomie

Since words are not very long, it is not a problem to iterate through the entire word and keep track of the position of the first vowel, and if there is a consonant. [code] first_vowel = -1 ## location of first vowel consonant_found = False ## assume no consonants t …

Member Avatar for woooee
0
860
Member Avatar for madtowneast

There are not any answers presumably because no one uses 5 nested dictionaries. State what you are trying to do and why a 5-deep dictionary is necessary, along with a simple example, 184 lines of code is more than someone wants to wade through for a question like this, so …

Member Avatar for woooee
0
362
Member Avatar for sofia85

First have you tried difflib or something like it, as this has to have already been done by someone? If you are using readlines to read the files or reading the recs into a list, we don't know, then these conditions will never be true, because letter or letters does …

Member Avatar for woooee
0
99
Member Avatar for huntaz556

You open movies.txt twice and don't close either one. Delete line #5, the first open is not used. It would work better if you open the file in a function. [code]def view_existing(): all_movies = open("movies.txt", "r").readlines() ## print the all_movies list and allow the user to select one ## something …

Member Avatar for TrustyTony
0
296
Member Avatar for as3g

Can't you just take the difference between price and priceW, and then multiply by rate. If you want to print out every increment, then some kind of loop is necessary, and should be in a function that you pass the prices, rate, and literal to print, since both calculations are …

Member Avatar for TrustyTony
0
94
Member Avatar for just_starting

You hit the Enter key without any data. You should know what the code does even if you get it from someone else. What is necessary to exit in this code? [code] in_str="" while in_str != "q": [/code]

Member Avatar for just_starting
0
167
Member Avatar for ao_py

You do not allow for an equal condition in the commented code. Since you did not say what "wrong" is, we can only guess.

Member Avatar for Gribouillis
0
2K
Member Avatar for sitmiller

[quote]for i in (hold2.split()[0:25]): AttributeError: 'list' object has no attribute 'split'[/quote]You want to split, etc. "i", not the list "hold2".

Member Avatar for woooee
0
203
Member Avatar for pelin

I think graphics has an undraw() method, you'll have to check to be sure, but set a variable to True or False. If True, call function_1 which undraws "standing" and draws "jump" and set variable=False. If False, call function_2 and do the reverse. It would be much easier if all …

Member Avatar for pelin
0
466
Member Avatar for imperialguy

This question is in all of the other forums and so has probably already been answered.

Member Avatar for woooee
0
487
Member Avatar for algrandjean1

sys.exit() is never a good idea. In this case Tkinter's quit() is the preferred way to exit. The program runs on my Slackware system with this modification to endProgram()[code] def endProgram (self): if self.state == 0: self.master.quit() else: print ("state is not zero -->", self.state) [/code]

Member Avatar for woooee
0
183
Member Avatar for peste19

[quote]but i know how to compare and find the age i just dont know how to show the name of the person[/quote]You want to use [code]for key, item in a_dictionary.items(): # # or for key in a_dictionary: if a_dictionary[key] == age: [/code]

Member Avatar for woooee
0
99

The End.