print [i+j+k for i in '123456789' for j in '0123456789' for k in '123456789' if (i==k)]
2015-05-22
r'''...'''注意这里的符号含义
本身r后面会接两个单引号''单引号内部的特殊字符享受不需要转椅的特权
但是为了使得内部的内容拥有换行的权限
又在这个内容的两边各加上了''两个单引号
最后形成'''******'''的形式
本身r后面会接两个单引号''单引号内部的特殊字符享受不需要转椅的特权
但是为了使得内部的内容拥有换行的权限
又在这个内容的两边各加上了''两个单引号
最后形成'''******'''的形式
2015-05-22
print [int(str(a)+str(b)+str(c)) for a in range(1,10) for b in range(0,10) for c in range(1,10) if a==c]
2015-05-21
print [str(a)+str(b)+str(c) for a in range(1,10) for b in range(1,10) for c in range(1,10) if a==c]
2015-05-21
sum = 0
x = 1
while x<100:
if x%2==1:
sum=sum+x
x=x+1
print sum
x = 1
while x<100:
if x%2==1:
sum=sum+x
x=x+1
print sum
2015-05-21
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2015-05-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-05-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-05-20
def greet(x='world'):
print 'Hello,'+x+'.'
greet()
greet('Bart')
print 'Hello,'+x+'.'
greet()
greet('Bart')
2015-05-20
def move(n, a, b, c):
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 a + '-->' + c
return
move(n-1, a, c, b)
print a + '-->' + c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
2015-05-20
import math
def quadratic_equation(a, b, c):
d = b*b - 4*a*c
return (-b + math.sqrt(d)) / (2.0*a) , (-b - math.sqrt(d)) / (2.0*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
d = b*b - 4*a*c
return (-b + math.sqrt(d)) / (2.0*a) , (-b - math.sqrt(d)) / (2.0*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-05-20