L = []
x = 1
sum = 0
while x <= 100:
sum = sum + x ** 2
x = x + 1
print sum
x = 1
sum = 0
while x <= 100:
sum = sum + x ** 2
x = x + 1
print sum
2015-10-29
sum = 0
x = 1
n = 1
while True:
sum=sum+(n+1)**(x-1)
x=x+1
if x>20:
break
print sum
x = 1
n = 1
while True:
sum=sum+(n+1)**(x-1)
x=x+1
if x>20:
break
print sum
2015-10-28
重点:
1. print u 语句 (pring r 语句)
2. 加上# -*- coding: utf-8 -*-
1. print u 语句 (pring r 语句)
2. 加上# -*- coding: utf-8 -*-
2015-10-28
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
2015-10-28
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n>=21:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n>=21:
break
print sum
2015-10-28
age = 20
if age<= 18 and age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
if age<= 18 and age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
2015-10-28
def generate_tr(name, score):
if score < 60:
return'<tr><td>%s</td><td style = "color: red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%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 style = "color: red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [ generate_tr(name, score) for name, score in d.iteritems()]
2015-10-28
def generate_tr(name, score):
if score < 60:
return'<tr><td>%s</td><td style = "color: red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%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 style = "color: red">%s</td></tr>' % (name, score)
else:
return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [ generate_tr(name, score) for name, score in d.iteritems()]
2015-10-28
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
注意 条件下的空格
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for l in L:
if l in s:
s.remove(l)
else:
s.add(l)
print s
注意 条件下的空格
2015-10-28
print [x*100 + y*10 + x for x in range(1,10) for y in range(0, 10)]
用两层就行吧,因为百位不为0,个位即使理论上可以是0,但是没意义嘛
用两层就行吧,因为百位不为0,个位即使理论上可以是0,但是没意义嘛
2015-10-28