enow.com Web Search

Search results

  1. Results from the WOW.Com Content Network
  2. Newton's Method (simple code) This is the method suggested in Think Python, 2nd edition, page 67, and doesn't need any library. Newton's method takes a number a and returns its square root as follows: y = (x + a/x) / 2. where x is an arbitrary estimation and y is a better estimation of a. def sqr_root(a):

  3. Write a function, square(a), that takes an array, a, of numbers and returns an array containing each of the values of a squared. At first, I had. def square(a): for i in a: print i**2 But this does not work since I'm printing, and not returning like I was asked. So I tried. def square(a): for i in a: return i**2

  4. 0. Using pure maths (no libraries) a square number can be determined in Python as follows: not n**0.5 % 1. As the square root of a square integer is an integer, this test uses modulo 1 equal to zero to test if the square root is an integer.

  5. This can be solved using the decimal module to get arbitrary precision square roots and easy checks for "exactness": import math. from decimal import localcontext, Context, Inexact. def is_perfect_square(x): # If you want to allow negative squares, then set x = abs(x) instead. if x < 0: return False.

  6. math - Integer square root in python - Stack Overflow

    stackoverflow.com/questions/15390807

    Long-hand square root algorithm. It turns out that there is an algorithm for computing square roots that you can compute by hand, something like long-division. Each iteration of the algorithm produces exactly one digit of the resulting square root while consuming two digits of the number whose square root you seek.

  7. types - Complex numbers in python - Stack Overflow

    stackoverflow.com/questions/8370637

    In python, you can put ‘j’ or ‘J’ after a number to make it imaginary, so you can write complex literals easily: >>> 1j 1j >>> 1J 1j >>> 1j * 1j (-1+0j) The ‘j’ suffix comes from electrical engineering, where the variable ‘i’ is usually used for current.

  8. Calculating the square numbers within a range (python)

    stackoverflow.com/questions/30254640

    For Python 3, replace the next method name with __next__. The usual Python range convention is to stop before you reach the high limit. To make this code comply with that convention, in the squares() generator change . while num <= hi: to . while num < hi: and in the Squares() class, change

  9. Nearest Square Function with Python - Stack Overflow

    stackoverflow.com/questions/45762619

    Implement the nearest_square function. The function takes an integer argument limit, and returns the largest square number that is less than limit. A square number is the product of an integer multiplied by itself, for example 36 is a square number because it equals 6*6. There's more than one way to write this code, but I suggest you use a ...

  10. You can simplify the problem though: divide your numbers by e.g. 10^100. The square root of 10^100 = 10^50. You can then use sqrt (a*b) = sqrt (a) * sqrt (b). @AlexMartelli, A quick test on my system shows that gmpy2.isqrt can calculate the integer square root of a 1,000,0000 digit number in less than 25 ms.

  11. The main idea of Python philosophy is to write simple code. To check if a number is an perfect square: return n**0.5 == int(n**0.5) When power to a float you can find the root of a number. This loses precision once your numbers get truly large: is_square(67108864**2 + 1) yields True.