L = [75, 92, 59, 68]
sum = 0.0
for score in L:
sum+=score
print sum / 4
sum = 0.0
for score in L:
sum+=score
print sum / 4
2016-03-28
age = 20
if age>=6 and age <18:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'前边结果不正确是因为逻辑不完整
或者就类似分数这一题,从逻辑上来说要求最严格的开始规定,就不太会出问题。但是实际操作时不可那能像题目那样逻辑那么清楚,所以自己将其限定严格非常必要
if age>=6 and age <18:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'前边结果不正确是因为逻辑不完整
或者就类似分数这一题,从逻辑上来说要求最严格的开始规定,就不太会出问题。但是实际操作时不可那能像题目那样逻辑那么清楚,所以自己将其限定严格非常必要
2016-03-28
def firstCharUpper(s):
return s.upper()[0]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s.upper()[0]+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2016-03-28
score = 55
if score>=60:
print 'passed'
else:
print 'failed'
if score>=60:
print 'passed'
else:
print 'failed'
2016-03-28
答案是这个:
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月。
低头思故乡。'''
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月。
低头思故乡。'''
2016-03-28