Lecture Notes on 18 Sep 2009 # Compute the square root newGuess = ((n / oldGuess) + oldGuess) / 2.0 Let us calculate the square root of 7 Iter OG NG Diff 1 3.5 2.75 0.75 2 2.75 2.6477 0.1023 3 2.6477 2.6458 0.0019 Diff = 2.65 - square root (7) oldGuess = n / 2.0 newGuess = ((n / oldGuess) + oldGuess) / 2.0 diff = oldGuess - newGuess if (diff < 0): diff = (-1) * diff while (diff > 1.0e-06): # Print three numbers in ascending order def main(): a = input ("Enter a number: ") b = input ("Enter a number: ") c = input ("Enter a number: ") if (a > b): a, b = b, a if (b > c): b, c = c, b if (a > b): a, b = b, a print a, b, c # This program prompts the user to enter the change to be returned in cents # and then prints out the amount of dollars, quarters, dimes, nickels, and # pennies that are to be returned def main(): # Prompt the user to enter change in cents change = input ("Enter change in cents: ") # Print change to be returned print print "Change is: ", dollars = change / 100 if (dollars > 0): print dollars, "dollars", change = change % 100 quarters = change / 25 if (quarters > 0): print quarters, "quarters", change = change % 25 dimes = change / 10 if (dimes > 0): print dimes, "dimes", change = change % 10 nickels = change / 5 if (nickels > 0): print nickels, "nickels", change = change % 5 if (change > 0): print change, "pennies" main()