d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
def generate_tr(name, score):
return '<tr><td>%s</td><td style="color:red">%s</td></tr>' % (name, score)
tds = [generate_tr(name,score) for name, score in d.iteritems()]
2018-12-29
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