help (abs)
import math
def quadratic(a, b, c):
m=b*b-4*a*c
u=math.sqrt(m)
x1=(-b+u)/(2*a)
x2 = (-b - u) / (2 * a)
return(x1,x2)
pass
print(quadratic(1, 3, -4))
def power(x):
return x * x
pass
def power3(x,n=3):
s=1
i=1
while i<=n:
s=s*x
i+=1
pass
return s
pass
print(power3(2,n=4))
def add_end(L=None):
if L is None:
L=[]
L.append('end')
return L
pass
print(add_end())
print(add_end())
def calc(numbers=[]):
sum = 0
for n in numbers:
sum = sum + n * n
return sum
calc([1,2,3])
def calc(*numbers):
sum = 0
for n in numbers:
sum = sum + n * n
return sum
calc(1,2,3)
nums = [1, 2, 3,4]
calc(*nums)
def person(name, age, **kw):
if 'city' in kw:
pass
if 'job' in kw:
pass
print('name:', name, 'age:', age, '其他',kw)
person('Jack', 24, 工作地点='Beijing', 住址='Chaoyang', 邮编=123456)
def person(name, age, *, city, job):
print('名字:',name, '年龄:',age, '城市',city, '工作:',job)
person('Jack', 24, city='Beijing', job='Engineer')
def person(name, age, *args, city, job):
print(name, age, args, city, job)
person('Jack', 24,'爱好','爱好','爱好',city='Beijing',job='Engineer')
def f1(a, b, c=0, *args, **kw):
print('a =', a, 'b =', b, 'c =', c, 'args =', args, 'kw =', kw)
def f2(a, b, c=0, *, d, **kw):
print('a =', a, 'b =', b, 'c =', c, 'd =', d, 'kw =', kw)
f1(1, 2)
f1(1, 2, c=3)
f1(1, 2, 3, 'a', 'b')
f1(1, 2, 3, 'a', 'b', x=99)
f2(1, 2, d=99, ext=None)
def mul(*num):
s=1
for n in num:
s=s*n
pass
return s
print(mul(5,6,7,9))
def fact(n):
if n==1:
return 1
return n * fact(n - 1)
print(fact(100))
|