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')
2018-05-05
sum = 0
x = 1
while x < 100:
sum = (x * 2 - 1) + sum
x = x + 1
print sum
x = 1
while x < 100:
sum = (x * 2 - 1) + sum
x = x + 1
print sum
2018-05-05
def average(*args):
s = 0.0
n = 0
if args:
for x in args:
s+=x
n+=1
return s/n
else:
return 0.0
print(average())
print(average(1, 2))
print (average(1, 2, 2, 3, 4))
s = 0.0
n = 0
if args:
for x in args:
s+=x
n+=1
return s/n
else:
return 0.0
print(average())
print(average(1, 2))
print (average(1, 2, 2, 3, 4))
2018-05-05
def greet(x='world'):
print('Hello,'+'%s.'%x)
greet()
greet('Bart')
print('Hello,'+'%s.'%x)
greet()
greet('Bart')
2018-05-05
def move(n, a, b, c):
if n==1:
print(a+'-->'+c)
return 0
else:
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
if n==1:
print(a+'-->'+c)
return 0
else:
move(n-1,a,c,b)
move(1,a,b,c)
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2018-05-05
#coding=utf-8
print "Python was started in 1989 by \"Guido\".\nPython is free and easy to learn."
print "Python was started in 1989 by \"Guido\".\nPython is free and easy to learn."
2018-05-05
x1 = 1
d = 3
n = 100
x100 = x1+d*(n-1)
s = (x1+x100)*n/2
print s
简直变态到无法容忍,s = (x1+x100)*n/2与s = (x1+x100)/2*n
有什么不同,结果就是不对,python啊
d = 3
n = 100
x100 = x1+d*(n-1)
s = (x1+x100)*n/2
print s
简直变态到无法容忍,s = (x1+x100)*n/2与s = (x1+x100)/2*n
有什么不同,结果就是不对,python啊
2018-05-05
d = {
'Adam':95,
'Lisa':85,
'Bart':59
}
for key in ['Adam','Lisa','Bart']:
print key, ':', d.get(key)
'Adam':95,
'Lisa':85,
'Bart':59
}
for key in ['Adam','Lisa','Bart']:
print key, ':', d.get(key)
2018-05-05
L=['1','2','3','4','5','6','7','8','9',]
M=['0','1','2','3','4','5','6','7','8','9',]
K=[a+b+c for a in L for b in M for c in M if a==c]
D=[]
for x in K:
D.append(int(x))
print D
我感觉自己是个神经病………………
M=['0','1','2','3','4','5','6','7','8','9',]
K=[a+b+c for a in L for b in M for c in M if a==c]
D=[]
for x in K:
D.append(int(x))
print D
我感觉自己是个神经病………………
2018-05-05
其实把参数a,b,c改成start,buffer,end就很容易理解了。从start出发,经过buffer,最后到达end
2018-05-05
print [x + y + x for x in '123456789' for y in '0123456789']
2018-05-05