Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36552

Re: new to python and programming at large.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.04; 'modify': 0.05; 'function,': 0.07; 'python': 0.09; 'input,': 0.09; 'loop.': 0.09; 'runs,': 0.09; 'def': 0.10; 'subject:python': 0.11; 'useful,': 0.13; 'aiming': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'input.': 0.16; 'subject:programming': 0.16; 'wrote:': 0.17; 'tries': 0.17; 'input': 0.18; 'appropriate': 0.20; 'math': 0.20; 'define': 0.20; 'all,': 0.21; 'trying': 0.21; 'import': 0.21; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'first,': 0.27; '(such': 0.27; 'run': 0.28; 'loop,': 0.29; 'function': 0.30; 'code': 0.31; 'url:python': 0.32; 'to:addr :python-list': 0.33; 'thanks': 0.34; 'pm,': 0.35; 'something': 0.35; 'received:org': 0.36; 'created': 0.36; 'except': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'url:org': 0.36; 'useful': 0.36; 'does': 0.37; 'why': 0.37; 'drop': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'url:docs': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'step': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; "you've": 0.61; 'first': 0.61; 'information': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.63; 'here': 0.65; 'url:tutorial': 0.93
X-Virus-Scanned amavisd-new at torriefamily.org
Date Wed, 09 Jan 2013 20:01:09 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:10.0.11) Gecko/20121115 Thunderbird/10.0.11
MIME-Version 1.0
To python-list@python.org
Subject Re: new to python and programming at large.
References <DF6E37C06383462E89D6FE634E3821EF@favour> <50EDB056.9060500@davea.name> <0C4AD4985823451295267B7505585C09@favour>
In-Reply-To <0C4AD4985823451295267B7505585C09@favour>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.357.1357786877.2939.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357786877 news.xs4all.nl 6898 [2001:888:2000:d::a6]:39268
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36552

Show key headers only | View raw


On 01/09/2013 07:45 PM, kwakukwatiah@gmail.com wrote:
> thanks so much it worked.I have tried and tried.look at what I was doing.
> me = raw_input("Enter a value:")
> from math import sqrt
> def squareroot(y):
> 
>     me = squareroot(y)
>     return squareroot(y)

Congratulations!  You've just created a recursive function!  If you call
your function, squareroot() with any value at all, the program will go
into an infinite loop and never output or return anything.

While recursive functions are useful, in your case I don't think that's
what you were aiming for.  What you need to do is drop the "me =" line,
which does nothing here except put it in a loop, and modify the "return"
line to return something useful (such as a calculation, perhaps created
by calling the appropriate function in the python math library) instead
of trying to return the result of calling your own function, which will
put it into a loop.

Step through the code in your head.  Consider what happens when someone
calls your squareroot function, with, say 5 as the input.  The first
line of the function runs, and then tries to run your function again
with 5 as the input, which then tries to run your function again with 5
as the input which then tries to run your function again with 5 as the
input, etc.  Recursion is very abstract at first, but i hope you
understand why this is happening.

For more information on how to define functions in general, see
http://docs.python.org/release/2.7/tutorial/controlflow.html#defining-functions

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: new to python and programming at large. Michael Torrie <torriem@gmail.com> - 2013-01-09 20:01 -0700

csiph-web