sum = 0
x = 1
while x < 100:
sum = x + 2
x = sum
print sum
x = 1
while x < 100:
sum = x + 2
x = sum
print sum
2018-06-04
可以实现的其中一种方法如下:
for x in range(1, 10):
for y in range(1, 10):
if x < y:
print str(x) + str(y)
for x in range(1, 10):
for y in range(1, 10):
if x < y:
print str(x) + str(y)
2018-06-04
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,":",d[key]
2018-06-04
x1 = 1
d = 3
n = 100
x100 = 1 + 3*99
s = ((x1 + x100)*100)/2
print s
d = 3
n = 100
x100 = 1 + 3*99
s = ((x1 + x100)*100)/2
print s
2018-06-04
sum = 0
n = 0
while True:
sum+=2**n
n+=1
if n>19:
break
print sum
n = 0
while True:
sum+=2**n
n+=1
if n>19:
break
print sum
2018-06-03
sum = 0
n = 0
x=1
while True:
x=2**n
sum+=x
n+=1
if n>19:
break
print sum
n = 0
x=1
while True:
x=2**n
sum+=x
n+=1
if n>19:
break
print sum
2018-06-03
思考题:
因为满足第一个条件,输出结果是teenager,不会向下执行了,所以不会输出adult,改正的话只需要把条件的顺序交换一下,把>=18的代码块放前面即可
因为满足第一个条件,输出结果是teenager,不会向下执行了,所以不会输出adult,改正的话只需要把条件的顺序交换一下,把>=18的代码块放前面即可
2018-06-03
L = ['Adam', 'Lisa', 'Bart']
L[0],L[2]=L[2],L[0]
print L
L[0],L[2]=L[2],L[0]
print L
2018-06-03
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop()
L.pop()
print L
L.pop()
L.pop()
print L
2018-06-03
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n = 0
sum = 0.0
for i in d.values():
sum = sum + i
n = n + 1
print sum/n
n = 0
sum = 0.0
for i in d.values():
sum = sum + i
n = n + 1
print sum/n
2018-06-02
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in zip(range(1,5),L):
print index, '-', name
for index, name in zip(range(1,5),L):
print index, '-', name