sum = 0
x = 1
while x < 100:
if x % 2 ==1:
sum += x
x = x + 1
print sum
x = 1
while x < 100:
if x % 2 ==1:
sum += x
x = x + 1
print sum
2019-08-23
首先呢,汉诺塔原理懂,但是懂得情况下让我写这段代码,我还真没有那个智商。我是带着答案看懂这段代码的,最重要的一点就是一定要注意每个步骤它的a,b,c参数对应的A,B,C是时刻在变的,并且代码里是一层套一层的递归,想要搞清楚怎样运行的,最好拿张纸,个人鄙见。
2019-08-23
t = ('a', 'b', ["('A', 'B')"])
print t
请问大神这样可以吗
print t
请问大神这样可以吗
2019-08-22
sum = 0
x = 1
n = 1
while True:
if n > 20:
break
sum = sum + x
x = pow(2,n)
n += 1
print sum
x = 1
n = 1
while True:
if n > 20:
break
sum = sum + x
x = pow(2,n)
n += 1
print sum
2019-08-22
sum = 0
x = 1
while x<100&&x%2==1:
sum+=x
print sum
x = 1
while x<100&&x%2==1:
sum+=x
print sum
2019-08-22
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
#print L[3]
print L[0]
print L[1]
print L[2]
#print L[3]
2019-08-21
涉及到短路运算,a or 'world',a不为null ,空字符串和0.所以结果是a;
第二个因为b是空字符串,所以结果是world
第二个因为b是空字符串,所以结果是world
2019-08-21
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
2019-08-21
score = 85
if score>=90:
print 'excellent'
elif score>=80&&a<90:
print 'good'
elif score>=60&&a<80:
print 'passed'
else score<60:
print 'failed'
if score>=90:
print 'excellent'
elif score>=80&&a<90:
print 'good'
elif score>=60&&a<80:
print 'passed'
else score<60:
print 'failed'
2019-08-21
def move(n, a, b, c):
if n ==1:
print a, '-->', c
return
move(n-1, a, c, b)
print a, '-->', c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
if n ==1:
print a, '-->', c
return
move(n-1, a, c, b)
print a, '-->', c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
2019-08-19
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0] + ':', x[1]
for x in s:
print x[0] + ':', x[1]
2019-08-19
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
else:
sum = sum + x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x % 2 == 0:
continue
else:
sum = sum + x
print sum
2019-08-19