Python Forum
Finding square roots using long division.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding square roots using long division.
#3
(Feb-22-2021, 09:54 AM)Serafim Wrote: If you want to continue beyond this you must add new groups of zeroes to "a", one group for the number of decimals you want

Eg. the square root of 3:
With your method you get 1.
Next step, decide the number of decimals, say 3.
Extend "a" to [03, 00, 00, 00]
and count with the same method

Thanks, seems easy for integers, but still clueless for floats as 1235.6789.
The coding is too difficult as have jobs:
1. In the driver code, need know length of float.
Need break in units of two based on that..

If make modifications in the Driver code as follows:

#Driver code 
x = 1235.789
# Find length of integer
y=x
length =0
"""
while (y > 0): 
    y //=100
    length+= 1
"""
while (y > 0): 
    if (y>=1):
        print 'integer part'
        y = y //100
        print 'y :', y
        length += 1
    elif (y <1) :
        print 'decimal part'
        y = y*100 
        y /= 100
        print 'y :', y
        length += 1
 
Then, get:

Output:

integer part
y : 12.0
integer part
y : 0.0
length : 2

Unable to find a way out.
Reply


Messages In This Thread
RE: Finding square roots using long division. - by jahuja73 - Feb-22-2021, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Zero Division Error Leo 2 1,261 Mar-25-2022, 05:56 AM
Last Post: Leo
  Division problem Eric7Giants 1 1,706 Nov-16-2019, 05:50 AM
Last Post: ndc85430
  Count how many carpets you need to fill room floor without multiplication/division Ech0ke 1 2,330 Apr-20-2019, 07:50 PM
Last Post: ichabod801
  Zero Division Error moga2003 4 3,100 Mar-07-2019, 02:15 AM
Last Post: moga2003
  Magic square! frequency 1 2,564 Dec-17-2018, 06:35 PM
Last Post: micseydel
  Square reverse sum(overloaded) shihomiyano 6 4,117 Aug-18-2018, 06:27 AM
Last Post: micseydel
  Perfect Square program forumer444 4 8,964 Sep-01-2017, 09:32 PM
Last Post: forumer444
  Magic Square Puzzle Harnick 1 4,893 Aug-09-2017, 04:51 PM
Last Post: nilamo
  Square Root on calculator MP1234593 1 7,971 Jun-06-2017, 06:58 PM
Last Post: nilamo
  List of square roots python py7 6 6,422 Apr-08-2017, 11:26 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020