d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.items()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
print d.items()
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2015-03-18
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print d.values()
sum = 0.0
for v in d.values():
sum=sum+v
s=sum/len(d)
print s
print d.values()
sum = 0.0
for v in d.values():
sum=sum+v
s=sum/len(d)
print s
2015-03-18
def average(*args):
sum = 0.0
if len(args) == 0:
return 0;
else:
for a in args:
sum += a
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 0;
else:
for a in args:
sum += a
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-03-18
def greet(name='world'):
print 'Hello,'+name+'.'
greet()
greet('Bart')
留个脚印?
print 'Hello,'+name+'.'
greet()
greet('Bart')
留个脚印?
2015-03-18
import math
def quadratic_equation(a, b, c):
t = math.sqrt(b * b - 4 * a * c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
t = math.sqrt(b * b - 4 * a * c)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2015-03-18
def square_of_sum(L):
sum = 0
for a in L:
sum += a*a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
函数定义特别哦,oc中都是方法,-(void)sendMessage:(nsstring *)msg
sum = 0
for a in L:
sum += a*a
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
函数定义特别哦,oc中都是方法,-(void)sendMessage:(nsstring *)msg
2015-03-18
最赞回答 / 小奇爱吐槽
这只是一种强制性语法规定,字符串只有加上了“”号或者‘’号才会被解释器解释成字符串。如果编译器或者解释器能够实现解释不加引号的字符串,你就可以不加引号,只是一种规则。
2015-03-17
age = 20 if age >= 6 and age<=18: age="">= 6 and <=18) print="" elif="" age="">= 18: print 'adult' else: print 'kid' 编辑器推荐PyCharm,缩进什么的都他帮你弄
2015-03-17
def square_of_sum(L):
sum = 0
for lv in L:
sum = sum + (lv*lv)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum = 0
for lv in L:
sum = sum + (lv*lv)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-03-17