In [ ]:
print("Hello,","world!")
Hello, world!
In [ ]:
import math
In [ ]:
help(math.erf)
dir(math)
Help on built-in function erf in module math:

erf(x, /)
    Error function at x.

Out[ ]:
['__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'acos',
 'acosh',
 'asin',
 'asinh',
 'atan',
 'atan2',
 'atanh',
 'ceil',
 'comb',
 'copysign',
 'cos',
 'cosh',
 'degrees',
 'dist',
 'e',
 'erf',
 'erfc',
 'exp',
 'expm1',
 'fabs',
 'factorial',
 'floor',
 'fmod',
 'frexp',
 'fsum',
 'gamma',
 'gcd',
 'hypot',
 'inf',
 'isclose',
 'isfinite',
 'isinf',
 'isnan',
 'isqrt',
 'lcm',
 'ldexp',
 'lgamma',
 'log',
 'log10',
 'log1p',
 'log2',
 'modf',
 'nan',
 'nextafter',
 'perm',
 'pi',
 'pow',
 'prod',
 'radians',
 'remainder',
 'sin',
 'sinh',
 'sqrt',
 'tan',
 'tanh',
 'tau',
 'trunc',
 'ulp']
In [ ]:
math.sqrt(a**2 + b**2)
<cell>1: error: Name "a" is not defined  [name-defined]
<cell>1: error: Name "b" is not defined  [name-defined]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 math.sqrt(a**2 + b**2)

NameError: name 'a' is not defined
In [ ]:
def pythagoras(a, b):
    asquared = a**2
    bsquared = b**2
    return math.sqrt(asquared + bsquared)

#print("Hello")

print(pythagoras(3, 4))
print(asquared)
<cell>9: error: Name "asquared" is not defined  [name-defined]
5.0
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [22], in <cell line: 9>()
      6 #print("Hello")
      8 print(pythagoras(3, 4))
----> 9 print(asquared)

NameError: name 'asquared' is not defined
In [ ]:
def pythagoras(a, b):
    a = a**2
    b = b**2
    return math.sqrt(a + b)
    #return pythagoras(a, b)
    print("bar")

#print("Hello")

print(pythagoras(3, 4))
5.0
In [ ]:
def pythagoras3(a, b, c):
    h = pythagoras(a, b)
    print("Hypotenuse of one face:", h)
    return math.sqrt(h**2 + c**2)
    #pythagoras(pythagoras(a, b), c)
    
print(pythagoras3(3, 4, 5))
Hypotenuse of one face: 5.0
7.0710678118654755
In [ ]:
def pythagoras(a, b):
    math.sqrt(a**2 + b**2)
    
h = pythagoras(3, 4)
print(h)
None
In [ ]:
from math import sqrt

def pythagoras(a, b):
    sqrt(a**2 + b**2)
    
def pythagoras3(a, b, c):
    return sqrt(pythagoras(a, b)**2 + c**2)

print(pythagoras3(4, 5, 6))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [36], in <cell line: 9>()
      6 def pythagoras3(a, b, c):
      7     return sqrt(pythagoras(a, b)**2 + c**2)
----> 9 print(pythagoras3(4, 5, 6))

Input In [36], in pythagoras3(a, b, c)
      6 def pythagoras3(a, b, c):
----> 7     return sqrt(pythagoras(a, b)**2 + c**2)

TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'
In [ ]:
def pythagoras(a, b):
    """
    Return the length of the hypotenuse of a right triangle with side lengths a and b.
    """
    r = sqrt(a**2 + b**2)
    print("Result is", r)
    return r

def distance(x1, y1, x2, y2):
    # Distance is the hypotenuse of a triangle with x distance as one side
    # and y distance as the other side
    xdist = x2 - x1
    # print("X distance is:", xdist)
    ydist = y2 - y1
    print("Y distance is:", ydist)
    return pythagoras(xdist, ydist)
    
print(distance(1, 1, 2, 0))
print(distance(0, -math.pi, math.sqrt(2), 13))
print(distance(13, 0, -math.pi, math.sqrt(2)))
help(pythagoras)
Y distance is: -1
Result is 1.4142135623730951
1.4142135623730951
Y distance is: 16.141592653589793
Result is 16.203425977071145
16.203425977071145
Y distance is: 1.4142135623730951
Result is 16.203425977071145
16.203425977071145
Help on function pythagoras in module __main__:

pythagoras(a, b)
    Return the length of the hypotenuse of a right triangle with side lengths a and b.