fork download
  1. '''calculates square roots, format input as (number of decimals, root)'''
  2. INPUT = [
  3. (0, 7720.17),
  4. (1, 7720.17),
  5. (2, 7720.17),
  6. (0, 12345),
  7. (8, 123456),
  8. (1, 12345678901234567890123456789)]
  9.  
  10. def findroot(num):
  11. '''finds root of the given number'''
  12. upper = 1
  13. lower = 0
  14. while lower != upper:
  15. lower = upper
  16. upper = ((num/upper) + upper) / 2
  17. return upper
  18.  
  19. def main():
  20. '''goes through each item in the input and prints the results'''
  21. for inputno in INPUT:
  22. sol = findroot(inputno[1])
  23. print(format(sol, '.{}f'.format(inputno[0])))
  24.  
  25. if __name__ == '__main__':
  26. main()
Success #stdin #stdout 0s 23304KB
stdin
Standard input is empty
stdout
88
87.9
87.86
111
351.00000000
111111110611111.0