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


Groups > comp.lang.python > #36513

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.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'classes.': 0.07; 'definitions': 0.07; 'function,': 0.07; 'parameter': 0.07; 'imports': 0.09; 'suggestions:': 0.09; 'thread,': 0.09; 'toss': 0.09; 'undefined.': 0.09; 'def': 0.10; 'subject:python': 0.11; 'bind': 0.16; 'expects': 0.16; 'field).': 0.16; 'purposes.': 0.16; 'spec,': 0.16; 'subject:programming': 0.16; 'string': 0.17; 'wrote:': 0.17; 'certainly': 0.17; 'else,': 0.17; 'working.': 0.17; 'input': 0.18; 'math': 0.20; 'import': 0.21; 'do.': 0.21; 'user.': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'expand': 0.26; 'fixed': 0.28; 'lines': 0.28; 'crash': 0.29; 'pile': 0.29; 'definition': 0.29; 'classes': 0.30; 'function': 0.30; '(and': 0.32; 'asking': 0.32; 'print': 0.32; 'int': 0.33; 'to:addr:python-list': 0.33; 'thanks': 0.34; 'pm,': 0.35; 'posting': 0.35; 'explain': 0.36; 'but': 0.36; 'problems': 0.36; 'two': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'takes': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'your': 0.60; "you've": 0.61; 'first': 0.61; 'close': 0.63; 'different': 0.63; 'email addr:gmail.com': 0.63; 'frequently': 0.65; 'reply': 0.66; 'header:Reply-To:1': 0.68; 'user,': 0.69; 'wish': 0.70; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'discovered': 0.83; 'confusing': 0.84; 'fortunately,': 0.84; 'matters.': 0.84; 'received:74.208.4.194': 0.84; 'str.': 0.91
Date Wed, 09 Jan 2013 13:00:54 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: new to python and programming at large.
References <DF6E37C06383462E89D6FE634E3821EF@favour>
In-Reply-To <DF6E37C06383462E89D6FE634E3821EF@favour>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:c1WT1lX6vMbz1IIWfz6ec6RtYWKgUPfgSuKb65NHUd2 iyrZu7Z5RBwH88mNp+x5ZDS0+i1c8UuCP1iCqNq7mJyh0lO3Vg L92Sb9JvshZpFsoQR4KlRyfKTr22mS/0Ldff6g2j7ScxF/r7zb gIb4uoarlMTI59tnM+6k0Q2oSMn6Bp9PKNJy+Dl9Kd8kPTaxq8 uPUDQPHS+BvP8SS75MSWCUse6ASGtiRtCYWSXcJN8PS02+hUY0 8tl+P3uzuHaCKQnDlhEkT66ZqRRI3761Mt2B3pCmL/oLrl9SHX NwQdO9ILzJ05U/DOS8GfAMHYl/wHc1AwnR0z9Z4/SF04aV6kg= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
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.332.1357754467.2939.python-list@python.org> (permalink)
Lines 66
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1357754467 news.xs4all.nl 6936 [2001:888:2000:d::a6]:60871
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36513

Show key headers only | View raw


On 01/09/2013 05:28 PM, kwakukwatiah@gmail.com wrote:
> thanks for ur help I wz able to do it.but I wish to expand it by asking a user to input a number for the sqrt to be calculated it I dd it this way but its not working.
>
>
> from math import sqrt
> number = raw_input('enter a number:')
> def number(y):
>     return number(Y)
>
>
>
>

Please don't keep posting new messages on the same topic.  When adding
to a thread, use Reply (and make sure python-list is in the to: or cc:
field).

This program has a pile of problems with it.

You've used the name 'number' for three different purposes.  Let me
explain what those lines do.

number = raw_input(...
    Capture a string from the user.  Type is str.

def number(y):
     toss out the string the user entered, and bind that name instead to
a function definition that takes a parameter y.

return number(Y)
    Attempt to call your own function recursively, but first crash since
Y is undefined.  Y is not the same as y.

Fortunately, you never actually call the function, by any name.

You never used the string you got from the user, but if you had fixed
everything else, you'd have discovered that sqrt() expects either an int
or a float.

Suggestions:
    put your imports first
    then put your function definitions and classes
    only then put your initialization and calls to those functions and
classes.
    Make sure you don't use the same name for two different purposes. 
It can frequently be okay, but it's certainly confusing for a beginner.
    Watch the case of any names you use.  It matters.

You don't have a spec, but perhaps this is close to what you want
(untested):


from math import sqrt

def squareroot(y):
    return sqrt(y)


number = float(raw_input('enter a number:'))
print squareroot(number)

 
-- 

DaveA

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


Thread

Re: new to python and programming at large. Dave Angel <d@davea.name> - 2013-01-09 13:00 -0500

csiph-web