Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > new to python and programming at large

Reply
Thread Tools

new to python and programming at large

 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      01-09-2013
Am 09.01.2013 22:05, schrieb http://www.velocityreviews.com/forums/(E-Mail Removed):
> pls I want to write a function that can compute for the sqrt root of
> any number.bt it not working pls help.


Whenever describing an error, be precise. In this particular case, we
have some sourcecode (which is good!) but what is still missing is what
exactly you see when running that code (output and error messages) and
what you expected instead.


> from math import sqrt
> def squareroot(self):
> x = sqrt(y)
> print x


In this very case, I also wonder if the tutorial you are learning from
assumes Python 2 while you are using Python 3. This is important,
because "print" is a special statement in Python 2 but a normal function
in Python 3.

That said, I see two errors here:
1. "self": This is customary used when you have a class function that
takes an instance of that class. This instance is then the first
parameter and called "self". Python doesn't enforce this, but you should
adhere to this convention to avoid confusion. Since you are not writing
a class, don't name this parameter "self".
2. There is no "y" in that code. I guess that if you renamed your "self"
to "y", you would get what you wanted.

Good luck and welcome to Python!

Uli

 
Reply With Quote
 
 
 
 
kwakukwatiah@gmail.com
Guest
Posts: n/a
 
      01-09-2013
pls I want to write a function that can compute for the sqrt root of any number.bt it not working pls help.
from math import sqrt
def squareroot(self):
x = sqrt(y)
print x
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: new to python and programming at large. kwakukwatiah@gmail.com Python 0 01-10-2013 02:45 AM
new to python and programming at large. John Gordon Python 1 01-09-2013 10:28 PM
new to python and programming at large kwakukwatiah@gmail.com Python 0 01-09-2013 09:03 PM
Re: new to python and programming at large. Dave Angel Python 0 01-09-2013 06:00 PM
Re: new to python and programming at large Chris Angelico Python 1 01-09-2013 03:43 PM



Advertisments