2,190 Posted Topics

Member Avatar for roe1and

This is a common exercise where you group records based on some indicator, an empty line in this case. This code prints the contents but you can also output to a file using .join)() and append a newline, "\n". [code]lit="""a=1 b=2 c=3 a=4 b=5 c=6 a=7 c=8 a=9 b=10 c=11""" …

Member Avatar for roe1and
0
308
Member Avatar for straylight

Your indentation is incorrect so it is difficult to tell what you are trying to do. "i" will never equal -1 (and you should not use "i", "l" or "O" as they can look like numbers) [code] elif i==-1:[/code] And this statement does not make sense because you seem to …

Member Avatar for straylight
0
239
Member Avatar for HoneyBadger

It is explained in [url=http://www.freenetpages.co.uk/hp/alan.gauld/tuttext.htm]this tutorial[/url]. Also a web search for "python string split" will turn up more examples. You can use a split and specify the character, or replace and then split() with the default=space(s).

Member Avatar for HoneyBadger
0
157
Member Avatar for layneb131

You can also use a list of lists [code]letters_to_numbers= [['ABC', 2], ['DEF', 3]] for test_it in ["A", "E", "C"]: print for group in letters_to_numbers: print "testing %s in %s" % (test_it, group[0]) if test_it in group[0]: print " the number for %s is %d" % (test_it, group[1]) # # or …

Member Avatar for woooee
0
490
Member Avatar for ohblahitsme

This statement will always yield True [code] elif decision == "north" or "east" or "west" # #It breaks down to elif decision == "north" or "east" or "west"[/code] and both "east" and "west" are not empty strings so either will evaluate to True. Instead use [code] elif decision in ["north", …

Member Avatar for woooee
0
287
Member Avatar for dineshswamy

If you are using Python3.X input is fine. If you are using Python2.x then input captures numbers, and raw_input captures strings.

Member Avatar for dineshswamy
0
135
Member Avatar for jone kim

Based on the sample data you provided, it would be simpler to find the row that starts with a number greater than the one you are looking for and check the previous row. [code]def compare_columns(matrix, number): for row in range(1, len(matrix)): if number <= matrix[row][0]: ## number is less than …

Member Avatar for jone kim
0
242
Member Avatar for Eclipse77

You only have to update the "display" variable and keep track of misses as in this snippet.[code]def new_display(secret, display, guess, misses): """Displays the replacement of underscores with letters that the user has guessed""" index=secret.find(guess) display_list=[ eachltr for eachltr in display ] if (index > -1) and (display_list[index]=="_"): ## not already …

Member Avatar for woooee
0
3K
Member Avatar for Kitty17

You should usr "r" instead of guess, and you have to add the letters guessed to letter-g. [code]r= input("How many rounds do you want to play? (even number only) ") r=int(r) print (" You only get %d turns to guess the letter" % (d)) print ("Player 1's turn to play …

Member Avatar for Lucaci Andrew
0
696
Member Avatar for weIIet

2**218 = 421249166674228746791672110734681729275580381602196445017243910144 and 2**50 = 1125899906842624 Either one is going to take a long time. As Tony said you should be using the decimal module. [quote]this is my program maybe you can find a solution it works but when numbers very big such as 2**50 it don't[/quote]Not unless there …

Member Avatar for Thisisnotanid
0
2K
Member Avatar for TLSK

Use GetValue().decode('utf-8')) or what ever character set you wish. Generally, when using a non-English language, you have to use .decode(). AFAIK-which isn't much when it comes to this- # -*- coding: utf-8 -*- means the program code can be written in utf-8 characters, so you can use Greek letters in …

Member Avatar for TLSK
0
243
Member Avatar for floatingshed

2 text fields requires 2 Entry (Dialogs). Although TextCtrl is generally used. A standard example for entering user name and password. [code]import wx class TextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Text Entry Example', size=(300, 100)) panel = wx.Panel(self, -1) basicLabel = wx.StaticText(panel, -1, "Basic Control:") basicText = wx.TextCtrl(panel, -1, "I've …

Member Avatar for floatingshed
0
103
Member Avatar for ljvasil

You possibly add to the dictionary on line 50, although we can't tell from the code if it is adding a new key or updating an existing one. FID_GC_dict[Cur_FID] = lr_Value You possibly want to use a copy of the dictionary and should add some print statements to see what …

Member Avatar for ljvasil
0
177
Member Avatar for Tashalla

You check self.hit and self.miss, not the remaining empty squares (so there is some discrepancy between the lists). [code] def check_hit_miss(self, coodinate): '''return True if coodinate in board.hit or board.missed, return False otherwise. ''' if (coodinate in self.hit) or (coodinate in self.missed): return True else: return False # # change …

Member Avatar for woooee
0
764
Member Avatar for Yoink

The simplest is to use a dictionary [code]classes_taken={classlistA:["CMSC 201", "CMSC 202", "CMSC 203"], classlistB:["MATH 151", "MATH 152"]} etc. [/code]If you want to use lists then you can just transfer the classes taken to the list, so you would have 3 classes_taken lists or one list with 3 sublists. You can …

Member Avatar for Yoink
0
193
Member Avatar for unigrad101

You have to know the relative coordinates of the square and create text usually at a middle location. You will probably want to set the font to use and it's size. To modify your drawing [code] X1 X2 X3 X4 Y1 | | | | Y2 _____|_____|_____ | | | …

Member Avatar for woooee
0
135
Member Avatar for oberlin1988

[QUOTE=;][/QUOTE] Print "word" within the bottom for loop, and print "s" within IsPalindrome. It is considered poor style to have one isolated call to main() at the end of the program, which is just a function that calls statements that are better left outside, because in large programs you look …

Member Avatar for Lucaci Andrew
0
3K
Member Avatar for aharrisii

You should also check for values between a certain range, i.e. someone can not enter one million or a letter.

Member Avatar for rny5
0
2K
Member Avatar for fishsticks1907

Most of the online tutorials cover [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutinput.htm]input and conversion[/url] from on data type to another.

Member Avatar for woooee
0
109
Member Avatar for layneb131

Assuming "How high" means the number of rows to print, use a for() loop instead: [code] for ctr in range(num2): print "row number", num+1 [/code]A link to [url=http://www.freenetpages.co.uk/hp/alan.gauld/tutinput.htm]getting input from the user[/url]. It's for Python 2.x but can be easily modified for 3.x.

Member Avatar for woooee
0
1K
Member Avatar for ulxlx

Dive into Python has a chapter on [url=http://www.diveintopython.net/installing_python/windows.html]installing Python[/url] for both the Python.org and ActiveState versions.

Member Avatar for ulxlx
0
335
Member Avatar for 69MASTER

"board" contains references to the same list, not separate lists. The following code lists the id's which are the same. One item in one list in then changed. The print statement shows that all lists reflect the change. To generate one row, see the last line and then use a …

Member Avatar for woooee
0
436
Member Avatar for PythonIsCool

A duplicate of this post [url]http://www.daniweb.com/software-development/python/threads/412751[/url]

Member Avatar for TrustyTony
0
170
Member Avatar for blindg35

Quoted to include [noparse][code] tags[/noparse].[QUOTE=blindg35;1761034]Hello guys, just joined the community. Found it through google. :) I am basically new to python, only couple of days of knowledge. I am trying to make all the words in a txt file appear in 4 or 5 in a row. so the txt …

Member Avatar for woooee
0
255
Member Avatar for ComputerGirlie

[quote]Some of those codes you posted I have not learned yet. The teacher wants us to post the first middle and last names on 3 separates lines using the whitespaces as the indexes[/quote] You did not state any limitations in your question, so how are we to know what you …

Member Avatar for ComputerGirlie
0
640
Member Avatar for Dillary

That's because of the while() loop in the function. Instead keep track of the number of times the button is clicked. [code]from Tkinter import * class App: def __init__(self,master): self.master=master self.returned_values = {} frame = Frame(master) frame.grid() self.Answer_entry = Entry(master) self.Answer_entry.grid(row = 0, column = 1, sticky=W) self.Answer_entry.focus_set() User_Answer=self.Answer_entry.get() self.attempts …

Member Avatar for Dillary
0
416
Member Avatar for Matjame

"f" is a local variable and does not exist outside of the function unless you return it (which you don't). Also, line 218, print updateprimepage(), will print None because nothing is returned from the function.

Member Avatar for woooee
0
2K
Member Avatar for floatingshed

That is impossible because we don't know what code makes it appear and we don't even know which one of the GUI toolkits you are using. Also include the version of Python you are using and the operating system.

Member Avatar for floatingshed
0
128
Member Avatar for moroccanplaya

Try it and see for yourself. If you have problems post the code you are using for assistance. "When you create a new text widget, it has no contents. To insert text into the widget, use the insert method and insert text at the INSERT or END indexes:" [url]http://effbot.org/tkinterbook/text.htm[/url]

Member Avatar for woooee
0
124
Member Avatar for winnar

[quote]The objective is to list the occurrences of vowels in a given word, such that for (word = yellow) and index spits out (e = 1, o = 1)[/quote]This (e = 1, o = 1) is not the position/occurrences so I am assuming you want to count the number of …

Member Avatar for woooee
0
238
Member Avatar for ustar

You would send the values to a function and return the amounts. [code]def payment(principle, monthly_interest_rate, amount_paid): """ assumes a payment is made every month so there are no penalties """ if principle > 0: ## loan is not paid off interest_due = monthly_interest_rate * principle if amount_paid < interest_due: print …

Member Avatar for woooee
0
1K
Member Avatar for floatingshed

This should work (note the single quote at the beginning and end-Python uses both/either) but print "soxxy" to be sure. soxxy = '"tools\sox.exe" "%s.wav" "%ssox.wav" compand 0.3,1 6:-60,-50,-30 -14 -90 0.2 gain -n -1' % (name, name)

Member Avatar for woooee
0
287
Member Avatar for moroccanplaya

Lists are the easiest and quickest way to work with data IMHO. You can then join the elements into one string [url]http://www.diveintopython.net/native_data_types/joining_lists.html[/url]. [code]a = "01101000011001010111100100000000000000000000" b = "011000100111100101100101" combined_list=[] combined_list.append(b) combined_list.append(a[len(b):]) ## slice off length of "b" print "".join(combined_list) ## result 01100010011110010110010100000000000000000000[/code]

Member Avatar for moroccanplaya
0
120
Member Avatar for Cayris

You would use a while() loop or function for this, Search the web for either as there are many examples of password entry. Some pseudo-code[code]def get_pw(): while 1: pw=raw_input() if pw is correct: return [/code]

Member Avatar for Cayris
0
138
Member Avatar for giancan

Another way is to use a third class as a wrapper. The buttons in the following code print the contents of the variable from the other class. Also, it is never a good idea to create two or more instances of a GUI at the same time. It can cause …

Member Avatar for woooee
0
314
Member Avatar for jobs

It's a trick question because you don't store the values in a separate variable (that's why we have lists), you use short_list[0].strip() short_list[1].strip() short_list[2].strip() or strip all of the values in short_list if you don't want to strip() each time. [CODE]short_list = ['a\n' , 'b\n', 'c\n'] for x in range(len(short_list)): …

Member Avatar for cementovoz
0
865
Member Avatar for Vkitor

You would have to store all of the initial values and change the values back when the button in pressed. Or, generally you use a class to run a Tkinter application so you can destroy the class instance and create it again. Some example code would help us help you …

Member Avatar for woooee
0
14K
Member Avatar for floatingshed

You have not declared Button1 in the code you posted so there is nothing to disable. But generally it is [code]b.config(state=DISABLED)[/code] where "b" is the button's ID as returned by Tkinter. Also, you import Tkinter in two different ways (pick one only) [code]import Tkinter from Tkinter import *[/code] Do not …

Member Avatar for woooee
0
189
Member Avatar for floatingshed

Generally you use GetLabel() or event.GetEventObject().GetLabel(). Search on those for some examples.

Member Avatar for woooee
0
63
Member Avatar for MBPFAN

You can condense all of the print statements if you want. [code]print """Welcome to The Great Text Adventure! One day you wake up, in a room, locked in by yourself. Could there be a key? In the room you see.""" [/code] You can also [url=http://www.diveintopython.net/native_data_types/lists.html#d0e5623]use a list[/url] to eliminate redundant …

Member Avatar for MBPFAN
0
1K
Member Avatar for arson09

The palindrome function only compares the first and last numbers. You have to compare all of them. To reverse an integer without converting to a string you divide by ten. [code]def palindrome(num_in): reversed_num = 0 whole = num_in while whole > 0: whole, remain = divmod(whole, 10) reversed_num = reversed_num*10 …

Member Avatar for woooee
0
238
Member Avatar for joryrferrell

In the OnPlus function, the program will sleep for 1*5000 seconds which is about 1 1/2 hours. In the OnMinus function also, you add/subtract one from value but it has no meaning i.e is not displayed. You should test each function individually as you create it, otherwise you will be …

Member Avatar for joryrferrell
0
160
Member Avatar for kungfubambi

Everything should go under the if statement (indents count in Python), or copy the file you want to process to a list and process the list. [code]def treeDir (arg, dirpath, basenames): workspace = dirpath roads_list = [] for f in basenames: if f.startswith('roads.'): fullf = os.path.join(dirpath,f) function_to_process_this_file(fullf) ## ## or …

Member Avatar for kungfubambi
0
245
Member Avatar for huskeraider

As Tony stated, you can iterate over a file [code]#f = open('lorumipsum.txt'); # simulate the file f=["Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim\n", "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea …

Member Avatar for Thisisnotanid
0
789
Member Avatar for sainitin

Quoted to show indentation. Use "count" instead. [code]S1="""AACAAGAAGAAAGCCCGCCCGGAAGCAGCTCAATCAGGAGGCTGGGCTGGAATGACAGCG CAGCGGGGCCTGAAACTATTTATATCCCAAAGCTCCTCTCAGATAAACACAAATGACTGC GTTCTGCCTGCACTCGGGCTATTGCGAGGACAGAGAGCTGGTGCTCCATTGGCGTGAAGT CTCCAGGGCCAGAAGGGGCCTTTGTCGCTTCCTCACAAGGCACAAGTTCCCCTTCTGCTT CCCCGAGAAAGGTTTGGTAGGGGTGGTGGTTTAGTGCCTATAGAACAAGGCATTTCGCTT CCTAGACGGTGAAATGAAAGGGAAAAAAAGGACACCTAATCTCCTACAAATGGTCTTTAG TAAAGGAACCGTGTCTAAGCGCTAAGAACTGCGCAAAGTATAAATTATCAGCCGGAACGA GCAAACAGACGGAGTTTTAAAAGATAAATACGCATTTTTTTCCGCCGTAGCTCCCAGGCC AGCATTCCTGTGGGAAGCAAGTGGAAACCCTATAGCGCTCTCGCAGTTAGGAAGGAGGGG TGGGGCTGTCCCTGGATTTCTTCTCGGTCTCTGCAGAGACAATCCAGAGGGAGACAGTGG ATTCACTGCCCCCAATGCTTCTAAAACGGGGAGACAAAACAAAAAAAAACAAACTTCGGG TTACCATCGGGGAACAGGACCGACGCCCAGGGCCACCAGCCCAGATCAAACAGCCCGCGT CTCGGCGCTGCGGCTCAGCCCGACACACTCCCGCGCAAGCGCAGCCGCCCCCCCGCCCCG GGGGCCCGCTGACTACCCCACACAGCCTCCGCCGCGCCCTCGGCGGGCTCAGGTGGCTGC GACGCGCTCCGGCCCAGGTGGCGGCCGGCCGCCCAGCCTCCCCGCCTGCTGGCGGGAGAA ACCATCTCCTCTGGCGGGGGTAGGGGCGGAGCTGGCGTCCGCCCACACCGGAAGAGGAAG TCTAAGCGCCGGAAGTGGTGGGCATTCTGGGTAACGAGCTATTTACTTCCTGCGGGTGCA CAGGCTGTGGTCGTCTATCTCCCTGTTGTTC""" for lit in ["GAAT", "CAA"]: print lit, S1.count(lit) [/code] [QUOTE=sainitin;1747579]I have text file as follows seq.txt >S1 AACAAGAAGAAAGCCCGCCCGGAAGCAGCTCAATCAGGAGGCTGGGCTGGAATGACAGCG CAGCGGGGCCTGAAACTATTTATATCCCAAAGCTCCTCTCAGATAAACACAAATGACTGC GTTCTGCCTGCACTCGGGCTATTGCGAGGACAGAGAGCTGGTGCTCCATTGGCGTGAAGT CTCCAGGGCCAGAAGGGGCCTTTGTCGCTTCCTCACAAGGCACAAGTTCCCCTTCTGCTT CCCCGAGAAAGGTTTGGTAGGGGTGGTGGTTTAGTGCCTATAGAACAAGGCATTTCGCTT CCTAGACGGTGAAATGAAAGGGAAAAAAAGGACACCTAATCTCCTACAAATGGTCTTTAG TAAAGGAACCGTGTCTAAGCGCTAAGAACTGCGCAAAGTATAAATTATCAGCCGGAACGA GCAAACAGACGGAGTTTTAAAAGATAAATACGCATTTTTTTCCGCCGTAGCTCCCAGGCC …

Member Avatar for TrustyTony
0
292
Member Avatar for Zeref

[quote]SELECT * FROM PLAYERS WHERE NAME = ''pete' OR '1'='1'' with an error message [/quote] There is a syntax error here that has nothing to do with MySQL or injection. Your query breaks down into '' pete ' OR ' 1 '=' 1 ' In the future please include the …

Member Avatar for woooee
0
287
Member Avatar for colejmc20

You should start a new thread with one of the questions only, and the code that you have tried. For example, where is the data coming from in the first question? If from a file, then the file has to be read.

Member Avatar for woooee
0
167
Member Avatar for spyhawk

All tutorials contain information on how to work with strings. [url]http://www.pasteur.fr/formation/infobio/python/ch01.html#d0e109[/url] [url]http://docs.python.org/library/stdtypes.html#string-methods[/url] [url]http://wiki.python.org/moin/BeginnersGuide/Programmers[/url]

Member Avatar for woooee
0
161
Member Avatar for imperfectluck1

Come up with a test suite, with known numbers and known results to test with. Also, you don't know if multiplication or division is done first so this line a= (sum1 / r*1.0) can lead to unexpected results. And I think that multiplication and division would evaluate left to right, …

Member Avatar for woooee
0
156
Member Avatar for ronvenna

It would be an else statement after the blankline code [code] if line.startswith('\n'): blankline = blankline + 1 else: if len(line.strip()) < shortest: shortest = len(line.strip()) # or better yet line = line.strip() if len(line) == 0: blankline = blankline + 1 else: if len(line) < shortest: shortest = len(line) …

Member Avatar for woooee
0
533

The End.