def firstCharUpper(s):
s=s[0].upper()+s[1:]
return s
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
s=s[0].upper()+s[1:]
return s
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-06-15
def average(*args):
sum =0.0
if len(args) ==0:
return sum
for x in args:
sum = sum +x
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum =0.0
if len(args) ==0:
return sum
for x in args:
sum = sum +x
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-06-15
def square_of_sum(L):
sum =0
for x in L:
sum = x*x+sum
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 = x*x+sum
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-06-15
因为 if当age=20时, age >= 6: 一样是成立的,而条件判断是从上至下的,因此执行到print 'teenager'已经跳出了……
解决办法,1、倒叙排列,先执行age >= 18
2、将判断语句多做条件限制age >= 6 and <18:
解决办法,1、倒叙排列,先执行age >= 18
2、将判断语句多做条件限制age >= 6 and <18:
2015-06-14
把list → ['A','B'] 换成
tuple → ('A','B')
tuple → ('A','B')
2015-06-14
因为少加了个,因为()有优先级的意义,所以('Adam')会被解释为字符串,如果要解析为tuple,则需要在后面加个额外的,
2015-06-14
因为第一次删除 Paul 之后,
L变成了['Adam','Lisa','Bart']
此时Bart的索引号由3变为了2
因此 正确答案应该是
L.pop(2)
L.pop(2)
L变成了['Adam','Lisa','Bart']
此时Bart的索引号由3变为了2
因此 正确答案应该是
L.pop(2)
L.pop(2)
2015-06-14