d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print d
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print d
2015-11-28
for x in [1,2,3,4,5,6,7,8,9,]:
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print xy
for y in [1,2,3,4,5,6,7,8,9]:
if x<y:
print xy
2015-11-28
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2015-11-27
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum=0.0
n=0
for i in d.itervalues():#用itervalues()方法迭代(取出)dict d中的value
sum=sum+i#计算总和
n=n+1#计数的作用,每迭代一次就增加1
print sum/n,sum,n#分别打印平均分,总和和人数,注意!!打印语句不要缩进!!打印语句是最后执行的代码,不需要缩进,如果缩进了,就成为了for循环里面的代码块,则打印了n次!!!!
sum=0.0
n=0
for i in d.itervalues():#用itervalues()方法迭代(取出)dict d中的value
sum=sum+i#计算总和
n=n+1#计数的作用,每迭代一次就增加1
print sum/n,sum,n#分别打印平均分,总和和人数,注意!!打印语句不要缩进!!打印语句是最后执行的代码,不需要缩进,如果缩进了,就成为了for循环里面的代码块,则打印了n次!!!!
2015-11-27
sum = 0
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
# 结果是2500
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
# 结果是2500
2015-11-27
L = [75, 92, 59, 68]
sum = 0.0
for x in L:
print x
sum = sum + x
print sum / 4
sum = 0.0
for x in L:
print x
sum = sum + x
print sum / 4
2015-11-27
#由于代码从上往下执行,所以一旦上方代码可以print就直接打印了,所以方法一改代码结构,方法二改代码顺序:
①
age = 20
if 18 > age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
②age = 20
if age >= 18:
print 'teenager'
elif age >= 6:
print 'adult'
else:
print 'kid'
①
age = 20
if 18 > age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
②age = 20
if age >= 18:
print 'teenager'
elif age >= 6:
print 'adult'
else:
print 'kid'
2015-11-27
score = 55
if score >=60:
print 'passed'
else :
print 'failed'
print 'End'
#注意缩进,同一语法的缩进一致
if score >=60:
print 'passed'
else :
print 'failed'
print 'End'
#注意缩进,同一语法的缩进一致
2015-11-27
score = 75
if score >= 60:
print 'your score is',score
print 'Congratulation!!!'
print 'I\'m sorry,failed!'
if score >= 60:
print 'your score is',score
print 'Congratulation!!!'
print 'I\'m sorry,failed!'
2015-11-26
t = ('a', 'b', ('A', 'B'))
print t
print t
2015-11-26