L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
index=index+1
print index, '-', name
for index, name in enumerate(L):
index=index+1
print index, '-', name
def average(*args):
if len(args)==0:
return 0.0
else :
return sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
else :
return sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2019-12-17
def move(n,a,b,c):
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
2019-12-17
def move(n,a,b,c):
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
x=1
y=1
if n<0:
print ('n must not zero')
else:
while n>1 and x<n:
x = x + 1
print a,'-->',b
print a,'-->',c
while n>1 and y<n:
y = y + 1
print b,'-->',c
move(4, 'A', 'B', 'C')
2019-12-17
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
if n > 20
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
if n > 20
break
print sum
2019-12-13
score = 60
if socre >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score < 60:
print 'faild'
else:
prinit 'passed'
if socre >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score < 60:
print 'faild'
else:
prinit 'passed'
2019-12-12
print 45678+0x12fd2
print"learn python in imooc"
print 100<99
print 0xff==255
print"learn python in imooc"
print 100<99
print 0xff==255
2019-12-12
print [int(m+n+m) for m in '123456789' for n in '0123456789']
2019-12-11
a为True,or运算返回a第一个输出hello,python
b为false,or运算返回world,第二个输出hello,world
b为false,or运算返回world,第二个输出hello,world
2019-12-11
def move(n,a,b,c):
if n<1:
print('n shoud be greater than zero')
return
if n==1:
print a,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4,'a','b','c')
if n<1:
print('n shoud be greater than zero')
return
if n==1:
print a,'-->',c
return
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4,'a','b','c')
2019-12-10
import math
def quadratic_equation(a, b, c):
t=b*b-4*a*c
m=math.sqrt(t)
if t<0:
print('equations has no real roots')
return
else:
x1=(-b+m)/(2*a)
x2=(-b-m)/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
t=b*b-4*a*c
m=math.sqrt(t)
if t<0:
print('equations has no real roots')
return
else:
x1=(-b+m)/(2*a)
x2=(-b-m)/(2*a)
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-12-10