In [1]:
print("Hello,","world!")
Hello, world!
In [3]:
x = 7
y = x * 2
x = x * 3
print("x is", x)
print("y is", y)
x is 21
y is 14
In [7]:
#print = 42
print("Hello") # prints hello
Hello
In [2]:
z / 7
<cell>1: error: Name "z" is not defined  [name-defined]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 z / 7

NameError: name 'z' is not defined
In [ ]:
z = 42
In [ ]:
x = 7
x = x * 6 # Huh? Nothing I write here does anything.

# Hello!
In [7]:
import math
a = 3
b = 4
math.sqrt(a**2 + b**2)
Out[7]:
5.0
In [9]:
from math import sqrt, log
sqrt(a**2 + b**2)
Out[9]:
5.0
In [10]:
math.sqrt(a**2 + b**2)
Out[10]:
5.0
In [11]:
help(sqrt)
Help on built-in function sqrt in module math:

sqrt(x, /)
    Return the square root of x.

In [12]:
help(log)
Help on built-in function log in module math:

log(...)
    log(x, [base=math.e])
    Return the logarithm of x to the given base.
    
    If the base not specified, returns the natural logarithm (base e) of x.

In [20]:
def pythagoras(a, b):
    return sqrt(a**2 + b**2)

pythagoras(3, 4)
Out[20]:
5.0
In [ ]:
def foo():
    a
    b
    c
In [30]:
def pythagoras(a, b):
    asquared = a**2
    bsquared = b**2
    print("Squares of the sides:", asquared, bsquared)
    return sqrt(asquared + bsquared)
    print("This will never be printed!")

pythagoras(3, 4)
#print(asquared)
Squares of the sides: 9 16
Out[30]:
5.0
In [41]:
def pythagoras3(a, b, c):
    h = pythagoras(a, b)
    # print("Hypotenuse of one face:", h)
    return sqrt(h**2 + c**2)

print(pythagoras3(3, 4, 5))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [41], in <cell line: 6>()
      3     # print("Hypotenuse of one face:", h)
      4     return sqrt(h**2 + c**2)
----> 6 print(pythagoras3(3, 4, 5))

Input In [41], in pythagoras3(a, b, c)
      2 h = pythagoras(a, b)
      3 # print("Hypotenuse of one face:", h)
----> 4 return sqrt(h**2 + c**2)

TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'
In [34]:
def pythagoras(a, b):
    sqrt(a**2 + b**2)
In [37]:
#print(pythagoras(3, 4))
h = pythagoras(3, 4)
print(h)
None
In [40]:
def pythagoras(a, b):
    sqrt(a**2 + b**2)

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

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

Input In [40], in pythagoras3(a, b, c)
      4 def pythagoras3(a, b, c):
      5     h = pythagoras(a, b)
----> 6     return sqrt(h**2 + c**2)

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

help(pythagoras)
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.