print("Hello,","world!")
Hello, world!
x = 7
y = x * 2
x = x * 3
print("x is", x)
print("y is", y)
x is 21 y is 14
#print = 42
print("Hello") # prints hello
Hello
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
z = 42
x = 7
x = x * 6 # Huh? Nothing I write here does anything.
# Hello!
import math
a = 3
b = 4
math.sqrt(a**2 + b**2)
5.0
from math import sqrt, log
sqrt(a**2 + b**2)
5.0
math.sqrt(a**2 + b**2)
5.0
help(sqrt)
Help on built-in function sqrt in module math:
sqrt(x, /)
Return the square root of x.
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.
def pythagoras(a, b):
return sqrt(a**2 + b**2)
pythagoras(3, 4)
5.0
def foo():
a
b
c
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
5.0
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'
def pythagoras(a, b):
sqrt(a**2 + b**2)
#print(pythagoras(3, 4))
h = pythagoras(3, 4)
print(h)
None
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'
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.