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')
2016-01-23
def average(*args):
n = len(args)
if n == 0:
return 0.0
else:
return sum(args)*1.0/ n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
n = len(args)
if n == 0:
return 0.0
else:
return sum(args)*1.0/ n
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2016-01-23
return sum 缩进了 然后怎么都只是第一个数的平方 例如[1,2][1,2,3]都返回第一个数的平方 之前都是空格 缩进这些问题 还得慢慢适应才行
2016-01-23
for x in [ 1,2,3,4,5,6,7,8 ]:
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x <y:
print x,y
for y in [ 1,2,3,4,5,6,7,8,9 ]:
if x <y:
print x,y
2016-01-23
楼下说的不对。。。
如果大于90表达式为true后面都不执行
如果小于90继续执行下一个判断,所以andscore<90是多余的
如果大于90表达式为true后面都不执行
如果小于90继续执行下一个判断,所以andscore<90是多余的
2016-01-23
def square_of_sum(L):
s = [x*x for x in L]
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
s = [x*x for x in L]
return sum(s)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2016-01-23
print [100*x+10*y+z for x in range(1,10) for y in range(10) for z in range(1,10) if x==z]
2016-01-22