已采纳回答 / 慕粉0315004
因为布尔运算有个短路原则,进行and运算时,如'a and b',如果'a'是'True',则整个计算结果必定取决于'b',所以就打印'b',这里的a和b都是字符串,都是True,所以打印b。or也是类似的。
2020-07-16
sum = 0
x = 0
while True:
if x > 99:
break
x = x + 1
if x%2==0:
continue
sum+=x
print sum
x = 0
while True:
if x > 99:
break
x = x + 1
if x%2==0:
continue
sum+=x
print sum
2020-07-15
sum = 0
x = 1
while x<=100:
if x%2!=0:
sum+=x
x=x+1
print sum
x = 1
while x<=100:
if x%2!=0:
sum+=x
x=x+1
print sum
2020-07-15
最新回答 / qq_棠梨煎雪故人来_03907185
因为本来就没有这个功能啊,你这个是复杂操作,是由多个原子操作组成的。python确实有许多库,但是这种太基础的也没谁会特意写啊。你要是想实现这个操作,可以自己写一个规则库,或者直接写个函数也行。你就会知道,这完全也没必要啊。有那导入或者调用的时间,功能早就实现完了。
2020-07-14
print [x*100+y*10+z for x in range(1,101) for y in range(0,101) for z in range(0,101) if x%100==z]
2020-07-14
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.items()]
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.items()]
2020-07-14
sum = 0
n = 0
while True:
sum = sum + 2**n
n = n+1
if n >=20:
break
print sum
n = 0
while True:
sum = sum + 2**n
n = n+1
if n >=20:
break
print sum
2020-07-14
def move(n,a,b,c):
if n==0:
return
elif n==1:
print a,"-->",c
else:
move(n-1,a,c,b),
print a,"-->",c
move(n-1,b,a,c)
move(4,'a','b','c')
if n==0:
return
elif n==1:
print a,"-->",c
else:
move(n-1,a,c,b),
print a,"-->",c
move(n-1,b,a,c)
move(4,'a','b','c')
2020-07-14
sum1=0
x = 1
while x<98:
x=x+2
sum1+=x
sum=sum1+1
print sum
x = 1
while x<98:
x=x+2
sum1+=x
sum=sum1+1
print sum
2020-07-13
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
n=0
for k, v in d.items():
sum = sum + v
print k,":",v
n=n+1
print 'average', ':', sum/n
sum = 0.0
n=0
for k, v in d.items():
sum = sum + v
print k,":",v
n=n+1
print 'average', ':', sum/n
2020-07-13
sum = 0
sum1=0
x = 1
while x<98:
x=x+2
sum1+=x
sum=sum1+1
print sum
sum1=0
x = 1
while x<98:
x=x+2
sum1+=x
sum=sum1+1
print sum
2020-07-13
L = [75, 92, 59, 68]
sum = 0.0
for nub in L:
sum+=nub
print sum / 4
sum = 0.0
for nub in L:
sum+=nub
print sum / 4
2020-07-13