while True:
x = input('give me a number: ')
print(2 ** int(x))
while True:
try:
x = input('give me a number: ')
print(2 ** int(x))
break
except:
pass
while True:
try:
x = input('give me a number: ')
print(2 ** int(x))
break
except ValueError:
print('that wasnt a number, try again')
while True:
try:
x = input('give me a number: ')
print(2 ** int(x))
break
except Exception as ex:
print('oops, that didnt work', ex, type(ex))
raise ConnectionError('why not', 10, 20,30, True, {1:2})
class AviadError(AttributeError ):
pass
x= 10
if x>0:
raise AviadError('x is too big', x)
assert x<5, 'x cannot be too big'
assert x<5, 'x cannot be too big'
bool( (False, 'x cannot be too big') )
def mymax(seq):
assert hasattr(seq[0], '__lt__'), 'seq is not comparable'
return seq[0]
mymax([0,1])
class Test:
pass
Test() < Test()
mymax( [Test(), Test()] )
seq = [Test(), Test()]
hasattr(seq[0], '__lt__')
dir(seq[0])
seq[0].__lt__(1)
dir(object)
try:
f = open('dir.txt')
10/0
finally:
f.close()
f.readline()
f = open('dir.txt')
10/0
f.readline()
import sys
def D(x):
return 10/x
def C(x):
return D(x)
def B(x):
return C(x)
def A(x):
return B(x) + B(x+1)
try:
z = A(0)
print(z)
except Exception as err:
traceback.print_exc()
tb.tb_frame.f_trace