print(abs(-5))
print(max(1,2))
print(max(1,2,3,4,5))
print(int('123'))
print(int(12.34))
print(float('12.34'))
print(str(1.23))
print(str(100))
print(bool(1))
print(bool(''))
a = abs
print(a(-1))
def my_abs(x):
if not isinstance(x,(int,float)):
raise TypeError('bad operand type')
if x>=0:
return x
else:
return -x
print(my_abs(-10))
def nop():
pass
import math
def move(x,y,step,angle=0):
nx = x + step*math.cos(angle)
ny = y - step*math.sin(angle)
return nx,ny
x,y = move(100,100,60,math.pi / 6)
print(x,y)
r = move(100,100,60,math.pi / 6)
print(r)
def my_power(x,n=2):
s = 1
while n>0:
n = n - 1
s = s * x
return s
print(my_power(5))
print(my_power(5,3))
def add_end(L=[]):
L.append('END')
return L
print(add_end([1,2,3]))
print(add_end(['a','b',3]))
print(add_end())
print(add_end())
print(add_end())
def add_end_M(L=None):
if L is None:
L = []
L.append('END')
return L
print(add_end_M())
print(add_end_M())
print(add_end_M())
def calc(numbers):
sum = 0
for n in numbers:
sum = sum + n*n*n
return sum
print(calc([1,2,3]))
print(calc((1,2,3,4,5)))
def calc_m(*numbers):
sum = 0
for n in numbers:
sum = sum + n*n
return sum
print(calc_m())
print(calc_m(1))
print(calc_m(1,2))
print(calc_m(1,2,3))
print(calc_m(1,2,3,4))
nums = [1,2,3]
print(calc_m(*nums))
def person(name,age,**kw):
print('name:',name,'age:',age,'other:',kw)
print(person('Michael',30))
aa = person('Bob',30,city='Beijing')
print(aa)
def person(name,age,**kw):
if 'city' in kw:
pass
if 'job' in kw:
pass
print('name:',name,'age:',age,'other:',kw)
person('Jack',24,city='Begin',addr='CHaoyang',zipcode=123456)
def person(name,age,*,city,job):
print(name,age,city,job)
person('Jack',24,city='Begin',job='Engineer')
def person(name,age,*args,city,job):
print(name,age,args,city,job)
person('Jack',24,(1,2,3),city='Begin',job='Engineer')
person('Jack',24,city='Begin',job='Engineer')
def person(name,age,*,city='beijing',job):
print(name,age,city,job)
person('Jack',24,job='Engineer')
def fact(n):
if n==1:
return 1;
return n*fact(n-1)
print(fact(100))
def fact_iter(num,product):
if num == 1:
return product
return fact_iter(num-1,num*product)
def fact(n):
return fact_iter(n,1)
print(fact(100))`这里写代码片`