sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2*x
n=n+1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum=sum+x
x=2*x
n=n+1
if n > 20:
break
print sum
2020-06-17
L = [75, 92, 59, 68]
sum = 0
sum1 = 0
avg = 0
for a in L:
sum = sum+a
sum1 = sum1+1
avg = sum/sum1
print (avg)
sum = 0
sum1 = 0
avg = 0
for a in L:
sum = sum+a
sum1 = sum1+1
avg = sum/sum1
print (avg)
2020-06-15
def square_of_sum(L):
arr = []
for n in L:
arr.append(n*n)
return sum(arr)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
arr = []
for n in L:
arr.append(n*n)
return sum(arr)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
2020-06-15
L = []
n=1
for i in range(1,101):
L.append(i*n)
n=n+1
print(sum(L))
print(L)
n=1
for i in range(1,101):
L.append(i*n)
n=n+1
print(sum(L))
print(L)
2020-06-15
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for lname in L:
if lname in s:
s.remove(lname)
else:
s.add(lname)
print(s)
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for lname in L:
if lname in s:
s.remove(lname)
else:
s.add(lname)
print(s)
2020-06-15
for x in [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:
print 10*x+y
else:continue
for y in [0,1,2,3,4,5,6,7,8,9]:
if x < y:
print 10*x+y
else:continue
2020-06-14
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==1:
sum+=x
else: continue
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==1:
sum+=x
else: continue
print sum
2020-06-14
print(45678+(0x12fd2))
print('Learn python in imooc')
print(bool(100<99))
print(bool(0xff==255))
运行成功
print('Learn python in imooc')
print(bool(100<99))
print(bool(0xff==255))
运行成功
2020-06-12
a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
在这里,a=true,所以第2行运行结果返回a
b等于空值,等于fales,非空值的world默认为true,第4行运行结果返回world
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
在这里,a=true,所以第2行运行结果返回a
b等于空值,等于fales,非空值的world默认为true,第4行运行结果返回world
2020-06-12
def move(n, a, b, c):
if n ==1 :
print a,"-->",c
return
print a,"-->",b
move(n-1, a, b, c)
print b,"-->",c
move(4, 'A', 'B', 'C')
if n ==1 :
print a,"-->",c
return
print a,"-->",b
move(n-1, a, b, c)
print b,"-->",c
move(4, 'A', 'B', 'C')
2020-06-09