Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'essentially': 0.04; 'ideally': 0.04; 'syntax': 0.04; 'output': 0.05; 'string.': 0.05; 'linux,': 0.07; 'list?': 0.07; 'string': 0.09; '[0,': 0.09; 'assuming': 0.09; 'function,': 0.09; 'len(x)': 0.09; 'parameter': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'steps:': 0.09; 'subject:Function': 0.09; 'runs': 0.10; 'python': 0.11; 'def': 0.12; 'assume': 0.14; '(it': 0.16; '2):': 0.16; '23,': 0.16; 'example)': 0.16; 'example).': 0.16; 'integers,': 0.16; 'normally,': 0.16; 'outputs': 0.16; 'parameter.': 0.16; 'range(0,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sequence.': 0.16; 'specifying': 0.16; 'usable': 0.16; 'all.': 0.16; 'language': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'command': 0.22; 'input': 0.22; 'example': 0.22; 'programming': 0.22; 'putting': 0.22; 'python?': 0.22; 'separate': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'replace': 0.24; '(or': 0.24; 'asking': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; "doesn't": 0.30; 'programming.': 0.30; 'specified': 0.30; 'code': 0.31; 'invoke': 0.31; 'stands': 0.31; 'terms.': 0.31; 'anyone': 0.31; 'file': 0.32; 'interface': 0.32; 'run': 0.32; 'text': 0.33; 'linux': 0.33; 'running': 0.33; 'call.': 0.33; 'message.': 0.35; 'knowledge': 0.35; 'display': 0.35; 'something': 0.35; 'case,': 0.35; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; "he's": 0.36; 'subject:Simple': 0.36; 'doing': 0.36; 'two': 0.37; 'list': 0.37; 'displays': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'previous': 0.38; 'that,': 0.38; 'does': 0.39; 'aside': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'tell': 0.60; 'numbers': 0.61; 'course': 0.61; "you're": 0.61; 'first': 0.61; 'you.': 0.62; 'back': 0.62; 'making': 0.63; 'kind': 0.63; 'happen': 0.63; 'interest': 0.64; 'more': 0.64; 'needing': 0.65; 'anything.': 0.68 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Creating a Simple User Interface for a Function Date: Thu, 25 Jul 2013 15:19:27 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.34 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 76 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374779986 news.xs4all.nl 15976 [2001:888:2000:d::a6]:47568 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51255 On 07/25/2013 12:03 PM, CTSB01 wrote: > I have the following code that runs perfectly: > > def psi_j(x, j): > rtn = [] > for n2 in range(0, len(x) * j - 2): > n = n2 / j > r = n2 - n * j > rtn.append(j * x[n] + r * (x[n + 1] - x[n])) > print 'n2 =', n2, ': n =', n, ' r =' , r, ' rtn =', rtn > return rtn > No it doesn't run perfectly. It'll get a syntax error on the print function call. That's assuming you're still using Python 3.3. You really need to start by specifying your environment, without making us look back through previous threads from you. > This code takes a string x = [0,1,1,1,2] for example That's not a string. A string would be like xx = psi_j("0abcd1234") Perhaps you mean list? And is it a list of integers, or of arbitrary numbers? Are there any constraints on the sizes or signs of those numbers? > (it must always begin with 0) and a parameter j, say 2, and outputs a string (x = [0, 1, 2, 2, 2, 2, 2, 3] in this example). > > It does this in two steps: First it decomposes some number m into a multiple of j and a remainder. Only if you replace the / with //. Or just use the function divmod(): n, r = divmod(n2, m) > Then it runs this decomposition through a function on the rtn.append line. > > Notice that this has cj - 1 terms where c is the number of terms in the input string and j is the parameter. Normally, we would like it to be able to calculate cj terms. > This is an issue with the function that I am more than happy to put aside for the moment. > > My key interest is to be able to make this program So far you have a function, not a program. If you put it in a text file and run it from python, it'll do nothing but display a syntax error message. And when you fix that, it'll just run without doing anything. usable for someone who has no knowledge of programming. In particular, I need some kind of user interface that prompts > the user to input a string (ideally just by putting in numbers in the form 011123334 for example) and a parameter, > and then displays the output sequence. This is essentially what the program already does but the idea is to make it usable > for even the most technologically disinclined. Ideally it would do this without needing to run Python at all. Then why are you asking on the Python forum? Or perhaps you mean without him knowing he's running Python? In that case, use a shebang line at the beginning, which will tell Linux to automatically invoke the specified program (or programming language in this case). > If anyone is able to make this happen in Python I would be eternally grateful. > If we assume you're running Python 3.3 on Linux, and the user is willing to us the terminal, then how about parsing the string from the command line he types? You can access it as011123334 a string from sys.argv, and convert it to separate numbers. Of course as it stands now, you cannot tell whether the user wanted 0,1,1,1,2,3,3,3,4 or 0, 111, 23, 3, 3, 4 or something else. -- DaveA