d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print ('Adam:',d.get('Adam'))
print ('Lisa:',d.get('Lisa'))
print ('Bart:',d.get('Bart'))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print ('Adam:',d.get('Adam'))
print ('Lisa:',d.get('Lisa'))
print ('Bart:',d.get('Bart'))
2016-09-29
# -*- coding: utf-8 -*-
print '静夜思\n床前明月光,\n疑是地上霜。\n举头望明月,\n低头思故乡。'
我这都成功了
print '静夜思\n床前明月光,\n疑是地上霜。\n举头望明月,\n低头思故乡。'
我这都成功了
2016-09-29
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print ("%s: %s" %(k,v))
print 'average', ':', sum / len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print ("%s: %s" %(k,v))
print 'average', ':', sum / len(d)
2016-09-29
score = 59
if score >= 60:
print 'you have passed and win the world'
if score < 60:
print 'you have lost all'
if score >= 60:
print 'you have passed and win the world'
if score < 60:
print 'you have lost all'
2016-09-29
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.itervalues():
sum += i
print sum / len(d)
sum = 0.0
for i in d.itervalues():
sum += i
print sum / len(d)
2016-09-29
score = 59
if score >= 60:
print 'you have passed'
if score < 60:
print 'you have lost the world'
if score >= 60:
print 'you have passed'
if score < 60:
print 'you have lost the world'
2016-09-29
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip([1,2,3,4],L):
print index, '-', name
for index, name in zip([1,2,3,4],L):
print index, '-', name
如果用的事3.X版本,代码应该是
print (u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
print (u'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
2016-09-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')
2016-09-29
def average(*args):
if len(args) == 0:
return 0.0
else:
return sum(list(args)) / (len(args) * 1.0)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
else:
return sum(list(args)) / (len(args) * 1.0)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2016-09-29