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-09-26
def quadratic_equation(a, b, c):
x1 = (-1*b+math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-1*b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
x1 = (-1*b+math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-1*b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
2015-09-25
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-09-25
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-09-25
def greet(x='world'):
print 'Hello,',x,'.'
greet()
greet('Bart')
print 'Hello,',x,'.'
greet()
greet('Bart')
2015-09-25
import math
def quadratic_equation(a, b, c):
if(b*b-4*a*c<0):
return 'Error'
else:
return (-b+math.sqrt(b*b-4*a*c))/(2*a),(-b-math.sqrt(b*b-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if(b*b-4*a*c<0):
return 'Error'
else:
return (-b+math.sqrt(b*b-4*a*c))/(2*a),(-b-math.sqrt(b*b-4*a*c))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-09-25
大概是这样:n个盘要从A移到C,应为要遵循那个算法,所以要将(n-1)个移动到B第n-1个要移动到C,遵循算法,(n-2)个就要移动到A,第n-2个移动到C,(n-3)个就要移动到B,这样就绕回来了.....真是绕啊!
2015-09-25
for x in range(1,10):
for y in range(1,10):
if x < y:
z=x*10+y
print z
for y in range(1,10):
if x < y:
z=x*10+y
print z
2015-09-25
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