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

NameError: name 'z' is not defined
In [ ]:
import math
math.sqrt(3**2+4**2)
Out[ ]:
5.0
In [ ]:
from math import sqrt, log
sqrt(3**2+4**2)
Out[ ]:
5.0
In [ ]:
math.pi
Out[ ]:
3.141592653589793
In [ ]:
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 [ ]:
def pythagoras(a, b):
    return sqrt(a**2 + b**2)

print(pythagoras(3, 4))
5.0
In [ ]:
def pythagoras(a, b):
    asquared = a**2
    bsquared = b**2
    return sqrt(asquared + bsquared)

print(pythagoras(3, 4))
print(asquared)
<cell>7: error: Name "asquared" is not defined  [name-defined]
5.0
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [25], in <cell line: 7>()
      4     return sqrt(asquared + bsquared)
      6 print(pythagoras(3, 4))
----> 7 print(asquared)

NameError: name 'asquared' is not defined
In [ ]:
def pythagoras(x, y):
    return sqrt(x**2 + y**2)
def pythagoras3(a, b, c):
    return sqrt(pythagoras(a, b)**2 + c**2)

print(pythagoras3(3, 4, 5))
7.0710678118654755
In [ ]:
def pythagoras(x, y):
    return sqrt(x**2 + y**2)
    print("Hello!")
def pythagoras3(a, b, c):
    return sqrt(pythagoras(a, b)**2 + c**2)

print(pythagoras3(3, 4, 5))
7.0710678118654755
In [ ]:
def pythagoras(x, y):
    print("Hello!")
    return sqrt(x**2 + y**2)
def pythagoras3(a, b, c):
    h = pythagoras(a, b)
    print("Hypotenuse of one side:", h)
    return sqrt(h**2 + c**2)

print(pythagoras3(3, 4, 5))
Hello!
Hypotenuse of one side: 5.0
7.0710678118654755
In [ ]:
def pythagoras(x, y):
    sqrt(x**2 + y**2)

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

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

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

TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'