d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2018-07-10
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for v in d.itervalues():
sum += v
print sum/len(d)
sum = 0.0
for v in d.itervalues():
sum += v
print sum/len(d)
2018-07-10
import math
def quadratic_equation(a, b, c):
if a==0:
return -c/b
delta = math.sqrt(b**2-4*a*c)
if delta<0:
return
else:
return (-b+delta)/(2*a),(-b-delta)/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if a==0:
return -c/b
delta = math.sqrt(b**2-4*a*c)
if delta<0:
return
else:
return (-b+delta)/(2*a),(-b-delta)/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-07-10
def average(*args):
n=0
avg=0.0
for i in args:
n=n+1
avg=avg+i
if n==0:
n=1
avg=avg/n
return avg
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
n=0
avg=0.0
for i in args:
n=n+1
avg=avg+i
if n==0:
n=1
avg=avg/n
return avg
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-07-10
for x in [ 1,2,3,4,5,6,7,8,9 ]:
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if x<y:
print str(x)+str(y)
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if x<y:
print str(x)+str(y)
2018-07-09
x1 = 1
d = 3
n = 100
sums=1
x100 =1
for i in range(0,99):
x100=x100+3
sums=sums+x100
print sums
d = 3
n = 100
sums=1
x100 =1
for i in range(0,99):
x100=x100+3
sums=sums+x100
print sums
2018-07-09
print [100*m+10*n+k for m in range(1,10) for n in range(0,10) for k in range(0,10) if m==k]
2018-07-09