- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 15
- Posts with Upvotes
- 12
- Upvoting Members
- 7
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
85 Posted Topics
Re: For a start, use 'elif'. This will fix the problem with input of '2'. [CODE] from math import * def main(): n=input("please enter the number you wish to check:") n=abs(n) if n < 2: print("this is not a prime number") elif n == 2: print("this is a prime number") elif … | |
Re: Here is some code to help you, but you need to do some work. [CODE] # define your own function that check for prime def isPrime(x): pass def primeFactorization(num): pfactors = [] while True: j = 2 while j < num+1: if num%j==0 and isPrime(j): num = num/j pfactors.append(j) break … | |
Re: You can refer to Chapter 18 of this book on how to create a deck class. Think Python: How to Think Like a Computer Scientist by Allen B. Downey [URL="http://www.greenteapress.com/thinkpython/thinkpython.html"]http://www.greenteapress.com/thinkpython/thinkpython.html[/URL] | |
Re: You can try this as suggested above: [CODE] keys = {} for pair in results: keys.setdefault(pair[0], []).append(pair[1]) [/CODE] | |
Re: To help you get started, for recursive function, think of (1) termination condition (2) each successive step solves a smaller subset of original problem. In your case, you can solve the problem by checking the first and last characters, and passing the shorter substring with first and last characters removed … | |
Re: When you want to perform mathematical operations, remember to cast your string tokens into integer/float using int()/float(). There is no need to use 'eval' in such cases. | |
Re: I think there is something wrong in your logic in the first place. Do you intend the sort the files by size? Your code is currently trying to sort a list of 2 elements containing just the file size and filename. | |
Re: [CODE] d = dict( [(k,v) for k,v in d.items() if len(v)>0]) [/CODE] | |
Re: another way is to use the method Enable() [CODE] # declare text ctrl txt = wx.TextCtrl(...,...) # write to text box txt.SetValue(...) # disable text box txt.Enable(False) # enable back text box txt.Enable(True) [/CODE] | |
Re: Try to replace line 18 with following line, remember to add 'import re'. [code] fname2 = re.sub(r'%s(.*)' % toBeStripped, r'\1', c[0]) + c[1] [/code] | |
Re: Go to [url]http://www.wxpython.org/onlinedocs.php[/url] and select "Alphabetical class reference", click on the widget that you are interested. This is normally what I do. However, as a beginner, I think "wxPython in Action" is a good book to begin with. | |
Re: Another way to to add the controls to a list. [CODE] # initialize controls text_ctrls = [] for x in xrange(1,4): text_ctrls.append(wx.StaticText(self, -1, "Text%d" %x, size=( (x-1)*20+10 ,-1))) # set attributes for x in xrange(3): text_ctrls[x].SetBackgroundColour(color[x]) # color can be initialized in a list somewhere [/CODE] | |
Re: You have to use threading. | |
Re: [code] wordsingle = [] worddouble = [] for word in l: if word in wordsingle: worddouble.append(word) else: wordsingle.append(word) return [ word for word in wordsingle if word not in worddouble] [/code] | |
Re: Should line 5 be "daughter_rev +=1" ? | |
Re: To check if an item exists in a list, just do: [CODE] if item in List1: # item found, add code here else: # item not found, add code here [/CODE] | |
Re: Add "import re" at the top of script and line 6 should be [code] x = re.compile(...) [/code] Line 9 has 1 additional '('. Line 12 can just be [code] line = '\n'.join(s) [/code] | |
Re: From your descriptions, it seems like you just want to strip "POST" and "is vulnerable.". Can't you just do [CODE] s= s.replace("POST","").replace("is vulnerable.","") [/CODE]? | |
Re: You can try the following, assuming frame is the parent of the panel. In def __init__ of class RefreshPanel, add self.parent = parent Then, instead of frame.SetStatusText(), use self.parent.SetStatusText() | |
Re: Since you already know what you want to do, just read up on how to read and write to file, and how to execute a loop. | |
Re: when you do [code] l.remove(l[i])[/code], your list 'l' reduces in size, so at some point, l[i] will give error because the index doesn't exist. | |
Re: This problem may be solved using 're' more easily. But just to correct your mistake, do the following: 1. Change line 11 to [CODE] return int(price[:c])+float(int(price[c+1:b]))/int(price[b+1:]) [/CODE] 2. Change line 15 to [CODE] return float(int(price[:b]))/int(price[b+1:]) [/CODE] 3. Change line 22 to [CODE] return price [/CODE] You should also change return … | |
Re: Line 79 should be [CODE]myCar.getVIN()[/CODE] instead of [CODE]myCar.getVIN('V81FDX')[/CODE] | |
Re: [CODE] line = '''<a href="http://www.gumtree.sg/?ChangeLocation=Y" rel="nofollow">Singapore</a>''' startpos = line.find('http') endpos = line.find('>') print line[startpos:endpos] [/CODE] | |
Re: list = [ ... ] should be m = [...] | |
Re: You can use wx.Notebook widget to have multiple tabs. | |
Re: Some mistakes: (1) userhex.lower should be userhex.lower() (2) "addhex" function is not returning any value (3) The values of your hextable should be string i.e. [CODE] 'a':"1010" # not 'a':1010 [/CODE] | |
Re: Can you try this? Try to bind wx.EVT_IDLE in the main frame or picture frame. [CODE] # create the binding to wx.EVT_IDLE self.Bind(wx.EVT_IDLE, self.OnIdle) def OnIdle(self, event): self.Refresh() [/CODE] | |
Re: For recursion, (1) there should be a terminating condition. (2) each successive call to the recursive function is solving a smaller subset of the problem. [CODE] def reduce(n): print n if n==3: # condition 1 return reduce((n-1)) # condition 2 reduce(12) [/CODE] | |
Re: This could be due to your terminal property. Try to set 'stty erase ^H' in your terminal. | |
Re: Please post your code so that we can help you. | |
Re: [code] a = ['1','2','3'] # use map b = map(lambda x:int(x), a) # or b = [ int(x) for x in a ] [/code] | |
Re: To help you get started, [code] filelocation = raw_input("Please enter file location:") [/code] | |
Re: [CODE] for line in open("file"): nums = [int(x) for x in line.split()] # nums now contains a list of integer # you can add/subtract/multiply by traversing the list [/CODE] | |
Re: I agree with group256. If you already know c++, you will appreciate the beauty and simplicity of Python. | |
Re: Here is something for you to start with [CODE] questions = [ ["What is the French word for one?", "un" ], ["What is the French word for two?", "deux"], ... ] right = 0 wrong = 0 for question in questions: ans = raw_input(question[0]) if ans.strip() == question[1]: ... else: … | |
Re: Why don't you try google app engine? It can be run on Python and it has quite a nice SDK. | |
Re: Your "b2" is initialized within an "if" block which may not be executed during runtime. So one way is to initialize "b2" outside the "if" block depending on what you want. [CODE] if dungeon2 == "Volcanic Valley": ... b2 = raw_input("Select your action:") # this line may not be executed. … | |
Re: You can try the 're' module. [code] line = "64 bytes from 74.125.45.106: icmp_seq=0 ttl=46 time=736.635 ms" mobj = re.search(r'^(\d+) bytes from ([0-9.]+): icmp_seq=(\d+) ttl=(\d+) time= ([0-9.]+) ms', line): print mobj.groups() # returns ('64', '74.125.45.106', '0', '46', '736.635') [/code] | |
Re: You can create an atom class and methods. [CODE] class atom: def __init__(self, name, x, y, z): self.name = name self.x = x self.y = y self.z = z def distance(self, other): '''Implement method to calculate distance between 2 atom''' [/CODE] | |
Re: [CODE] for line in open('testconn.txt'): if line.startswith('Domain') or line.startswith('Referer'): print line [/CODE] | |
Re: Your constructor (__init__) is defined as such [CODE] def __init__(self, tracker, timestamp): [/CODE] So when you create an instance of the class, it should be [CODE] newOrder = Order(orderNumber, timestamp) [/CODE] Alternately, change your __init__() as [CODE] def __init__(self, tracker): [/CODE] | |
Re: Your description was not very clear, not sure how you want to layout your control. You can try this below, it adds some padding. [CODE] sizer.Add(fnameLabel, 0, wx.ALIGN_RIGHT|wx.TOP|wx.LEFT, 5) sizer.Add(self.fname, 0, wx.RIGHT|wx.TOP|wx.LEFT, 5) [/CODE] | |
Re: You can try the wx.grid control. | |
Re: This may be what you want, to return a list of items below the mean. [CODE] def mean(alist): belowMean = [] mean = sum(alist) / len(alist) for item in alist: if item<mean: belowMean.append(item) return belowMean [/CODE] | |
Re: I suppose when he type [CODE] words = line.split(p) [/CODE] he meant [CODE] words = p.split() [/CODE] | |
Re: Did you install SendKeys module? I think it is a pre-requisite. | |
Re: You can first try to follow the tutorial at [url]http://www.python.org/doc/[/url]. Alternatively, you can search online and you will find some wonderful free resources. Then come back to here when you have queries regarding the syntax. | |
Re: [CODE] import re target = '<name value>my name is</name value>' mobj = re.search('<.*>(.*)</.*>', target) print mobj.groups()[0] [/CODE] |
The End.