Search code examples
pythonspyder

square root function on Python using Spyder


I'm just starting out using both Python under Spyder. I was about to do a simple square root calculation. I see that in Python, you need to do an "import math". I did that in Spyder and got an error: 'math' imported but unused. I tried using sqrt() but that threw an error. There's something fundamental I'm missing here. I did a bunch of searching and still have not been able to figure this issue out. Any help would be greatly appreciated.

thanks! clem


Solution

  • I can think of 3 options.

    1:

    import math
    
    n = 5
    
    print(math.sqrt(n))
    

    2:

    from math import sqrt
    
    n = 5
    
    print(sqrt(n))
    

    3:

    n = 5
    
    print(n ** 0.5)