0% found this document useful (0 votes)
5 views2 pages

explanation shit sa code

The document explains a program that approximates the square root of a number using Newton's Method, utilizing two variables: gf (Guess Factor) and qf. The program continuously prompts the user for input, starts with an initial guess, refines it through iterations, and prints each step until the guess is sufficiently accurate. It is designed to enhance understanding of square roots and Newton's Method by allowing users to see the calculation process in detail.

Uploaded by

wabe.pauljames33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

explanation shit sa code

The document explains a program that approximates the square root of a number using Newton's Method, utilizing two variables: gf (Guess Factor) and qf. The program continuously prompts the user for input, starts with an initial guess, refines it through iterations, and prints each step until the guess is sufficiently accurate. It is designed to enhance understanding of square roots and Newton's Method by allowing users to see the calculation process in detail.

Uploaded by

wabe.pauljames33
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Both qf and gf are variables used to approximate the square root of a number using Newton’s Method

gf (Guess Factor)

●​ gf is the current guess for the square root.


●​ The program starts with an initial guess (number_float / 2).
●​ It keeps improving this guess in each loop.

How It Works (Step by Step):

1.​ Keeps Running Until You Exit


○​ The program keeps asking for numbers until you type "exit".
○​ This allows you to calculate many square roots without restarting.
2.​ Takes User Input
○​ You type a number.
○​ The program converts it into a decimal (float).
3.​ Starts with a Guess
○​ It starts by guessing that the square root is half of the number.
○​ Another value (qf) is used to help with calculations.
4.​ Refines the Guess in a Loop
○​ The program checks if the guess is close enough to the real square root.
○​ If not, it improves the guess using this formula:​
python​
CopyEdit

5.​
6.​ This process makes the guess more accurate each time.

Prints Each Step

●​ Every time the guess improves, it prints the current guess (gf).
●​ You can see how the guess gets closer to the real square root.

Stops When the Guess is Accurate

●​ If the difference between guesses is very small (1.0e-15), the loop stops.
●​ The final answer is printed.

Repeats Until You Type "exit"

●​ After one calculation, you can enter another number.


●​ If you type "exit", the program stops.

Why is This Useful?

●​ Helps you understand how square roots work without a calculator.


●​ Shows Newton’s Method in action (used in real-world math problems).
●​ Lets you see every step of the calculation instead of getting the answer instantly.

You might also like