L = [5,9] ;
def area_of_circle(x):
return 3.14*x*x
for a in L:
s = area_of_circle(a)
print s
def area_of_circle(x):
return 3.14*x*x
for a in L:
s = area_of_circle(a)
print s
2019-07-03
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]
2019-07-03
for x in range(1,10):
for y in range(0,10):
if x>y:
print str(x)+str(y)
for y in range(0,10):
if x>y:
print str(x)+str(y)
2019-07-03
a or 'world',a是True,所以直接返回a;b or 'world',b是空,所以是False,因为world是True,所以返回world
2019-07-03
L = ['Adam', 'Lisa', 'Bart']
L.reverse()
print L
L.reverse()
print L
2019-07-03
L = ['Adam', 'Lisa', 'Bart']
B = L
L = []
n = 0
for i in B:
n -=1
L.append(B[n])
print L
B = L
L = []
n = 0
for i in B:
n -=1
L.append(B[n])
print L
2019-07-03
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
for index, name in enumerate(L):
print index+1, '-', name
for x in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
for y in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
if str((x * 10 + y)).__len__() == 2:
print(x * 10 + y)
for y in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
if x < y:
if str((x * 10 + y)).__len__() == 2:
print(x * 10 + y)
2019-07-01
(n代表第n项,例如第1项的和,则待入n 改变if的大于2)
sum = 0
x = 1
n = 1
while True:
if n > 20:
break
x = 2 ** (n - 1)
sum += x
n += 1
print sum
sum = 0
x = 1
n = 1
while True:
if n > 20:
break
x = 2 ** (n - 1)
sum += x
n += 1
print sum
2019-07-01