## Square Root

A forum for general discussion of the Python programming language.

### Square Root

How to find square root in a number using Python 3.2?
Last edited by Mekire on Thu Dec 19, 2013 3:53 am, edited 1 time in total.
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Re: Square Root

The same way you do it in python 2.x.

Try this.

Potential solution:
Code: Select all
`def square_root(number,iterations=100):    guess = number/2.0    for _ in range(iterations):        guess -= (guess**2-number)/(2*guess)    return guess`

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Square Root

Just use math.sqrt().
Friendship is magic!

R.I.P. Tracy M. You will be missed.

stranac

Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

### Re: Square Root

Boo. You sayin' my Newton's Method approximation isn't good enough for ya?

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Square Root

Mekire wrote:Boo. You sayin' my Newton's Method approximation isn't good enough for ya? :(

-Mek

+1
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Square Root

Or you could use this.

Code: Select all
`root ** (1 / index)`

That's probably how math.sqrt() is written, anyway.
Proverbs 26:14 describes me a bit too well.

Version: Python 3.4.3

https://github.com/4of92000
https://github.com/PythonForum/

XndrK

Posts: 208
Joined: Sat Jun 15, 2013 7:57 pm

### Re: Square Root

I tend to use **0.5 for my square roots, but that's not how math.sqrt() works actually: http://stackoverflow.com/questions/3270 ... math-sqrtx
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: Square Root

I was wrote a python program for find solutions of quadratic equation( aX² + bX + c ). Code is here. But something is wrong with finding square root. Please help me to solve this problem. Quadratic equation solving formula is,

x = (-b ± (squareroot(b² - 4ac))) / (2*a)

Code: Select all
`X1 = 0X2 = 0a = int(input('Input A :- '))if (a == 0) : print('No Solution.')else :    b = int(input('Input B :- '))    c = int(input('Input C :- '))    if (((b**2)-(4*a*c)) > 0) :        X1 = (-b+(math.sqrt(b**2-4*a*c)))/(2*a)        X2 = (-b-(math.sqrt(b**2+4*a*c)))/(2*a)        if (X1 == X2) : print('\nSolution =',X1)        else : print('\nSolotions =',X1,',',X2)    else : print('\nNo Solution.')`
Last edited by Mekire on Fri Dec 20, 2013 8:11 am, edited 1 time in total.
Reason: Images too annoying; removed.
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Re: Square Root

You never imported the math module.

Also please don't upload images if a paste with code tags would suffice.

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Square Root

You are creating problems instead of trying to solve them.
What would you do if someone asked you to help because "something went wrong"?
How would you yourself, looking at your own post, figure out what was the error?
Finally: screenshots will always be much worse than text, point.
ochichinyezaboombwa

Posts: 203
Joined: Tue Jun 04, 2013 7:53 pm

### Re: Square Root

Thank you all of you. Problem was solved. My heartiest sorry for my mistakes. I'm never do that. Again I want to say THANK YOU...
My Python Version is 3.2.3
b849961@drdrb.com

Posts: 13
Joined: Thu Oct 24, 2013 12:41 pm

### Who is online

Users browsing this forum: No registered users and 3 guests