sum = 0
x = 1
while x<=100:
if x%2!=0:
sum+=x
x+=1;
print sum
x = 1
while x<=100:
if x%2!=0:
sum+=x
x+=1;
print sum
2015-08-17
sum=0
x=1
while True:
sum+=x
x=x+2
if x>100:
break
if x%2>0:
continue
print sum
x=1
while True:
sum+=x
x=x+2
if x>100:
break
if x%2>0:
continue
print sum
2015-08-17
sum=0
x=1
n=1
while True:
x=2**(n-1)
num+=x
n+=1
if n>20:
break
print sum
x=1
n=1
while True:
x=2**(n-1)
num+=x
n+=1
if n>20:
break
print sum
2015-08-17
def average(*args):
if not args:
return 0.0
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if not args:
return 0.0
return float(sum(args))/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-08-16
print [int(a + b + c) for a in '123456789' for b in '0123456789' for c in '0123456789' if a == c ]
2015-08-15
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2015-08-15
a是非空字符串,布尔运算时python将其当做true,所以第一行结果返回的是a,而a是字符串,所以最终结果就是输出字符串的内容。
b是空字符串,布尔运算时将其当做false,所以第二行的结果取决于后面的字符串,于是返回的就是后面字符串的内容。
b是空字符串,布尔运算时将其当做false,所以第二行的结果取决于后面的字符串,于是返回的就是后面字符串的内容。
2015-08-15