for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x>=y:
continue
print x+y
for y in ['1','2','3','4','5','6','7','8','9']:
if x>=y:
continue
print x+y
2015-05-10
print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(1,10) if a==c]
2015-05-10
def greet(a='world',b='Hello'):
print "%s,%s."%(b,a)
print "%s,%s."%(b,a)
2015-05-10
先假设只有1步和只有2步的,然再改2步的
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1, a, c ,b)
print a,'-->',c
move(n-1, b, a ,c)
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1, a, c ,b)
print a,'-->',c
move(n-1, b, a ,c)
2015-05-10
def quadratic_equation(a, b, c):
chg = math.sqrt(b*b - 4*a*c)
return (-b+chg)/(2*a) , (-b-chg)/(2*a)
自己推了一遍才 做。。
坑爹算式必须都括号起来。。。
chg = math.sqrt(b*b - 4*a*c)
return (-b+chg)/(2*a) , (-b-chg)/(2*a)
自己推了一遍才 做。。
坑爹算式必须都括号起来。。。
2015-05-10
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=x*2
n=n+1
if n>20:
break
print sum
2015-05-10
def square_of_sum(L):
sum = 0
for x in L:
sum += x**2
return sum
sum = 0
for x in L:
sum += x**2
return sum
2015-05-10
def square_of_sum(L):
sum = 0
for x in L:
sum = sum +x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for x in L:
sum = sum +x*x
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-05-10
#条件过滤#列表生成式的 for 循环后面还可以加上 if 判断。(1)isinstance(x, str) 可以判断变量 x 是否是字符串;
(2)字符串的 upper() 方法可以返回大写的字母。
(2)字符串的 upper() 方法可以返回大写的字母。