def toUppers(L):
return [x.upper() for x in L if isinstance(x,str)]
return [x.upper() for x in L if isinstance(x,str)]
def generate_tr(name, score):
if score>60:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
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()]
if score>60:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
else:
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()]
2015-08-29
sum = 0
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
x = 1
while x < 100:
sum = sum + x
x = x + 2
print sum
2015-08-29
当 age = 8 时,结果正确,但 age = 20 时,为什么没有打印出 adult?
如果要修复,应该如何修复?
答:应该从大到小来写
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
这样当 age = 20 时候会打印 adult
如果要修复,应该如何修复?
答:应该从大到小来写
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
这样当 age = 20 时候会打印 adult
2015-08-29
score = input("Input:")
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
觉得这样比较好玩
if score >=90:
print 'excellent'
elif score >=80:
print 'good'
elif score >=60:
print 'passed'
else:
print 'failed'
觉得这样比较好玩
2015-08-29
('a', 'b', ('A', 'B'))与('a', 'b', ['A', 'B'])一样吗?明显不一样吧。
2015-08-29
from __future__ import division
def average(*args):
if len(args)==0:
average=0.0
else:
average=sum(args)/len(args)
return average
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
def average(*args):
if len(args)==0:
average=0.0
else:
average=sum(args)/len(args)
return average
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-08-29
L = ['Adam', 'Lisa', 'Bart', 'Paul']
ll=zip(range(1,5),L)
for index, name in ll:
print index, '-', name
ll=zip(range(1,5),L)
for index, name in ll:
print index, '-', name
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2015-08-28
s = set(['adam','bart'])
print 'adam' in s
print 'bart' in s
print 'adam' in s
print 'bart' in s
2015-08-28
def greet(a='world'):
print 'Hello,'+a+'.'
greet()
greet('Bart')
print 'Hello,'+a+'.'
greet()
greet('Bart')
2015-08-28