d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2018-12-29
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print float(sum(d.values()))/len(d)
print float(sum(d.values()))/len(d)
2018-12-29
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for score in d.itervalues():
sum+=score
print sum/len(d)
sum = 0.0
for score in d.itervalues():
sum+=score
print sum/len(d)
2018-12-29
def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2018-12-29
def average(*args):
return 0.0 if (len(args)==0) else float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
return 0.0 if (len(args)==0) else float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-12-29
def average(*args):
return 0.0 if (len(args)==0) else sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
return 0.0 if (len(args)==0) else sum(args)*1.0/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-12-29
def greet(char='world'):
print 'Hello,',char,'.'
greet()
greet('Bart')
print 'Hello,',char,'.'
greet()
greet('Bart')
2018-12-29
def move(n, a, b, c):
if n == 1:
print a, '-->', c
return
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
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
move(4, 'a', 'b', 'c')
2018-12-29