def square_of_sum(L):
L1 = []
for x in L:
L1.append(int(x*x))
return sum(L1)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
L1 = []
for x in L:
L1.append(int(x*x))
return sum(L1)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-11-27
L1 = []
for x in range(1,101):
L1.append(int(x*x))
print (sum(L1))
for x in range(1,101):
L1.append(int(x*x))
print (sum(L1))
2018-11-27
for x in ['1', '2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y :
print x + y
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y :
print x + y
2018-11-27
答案有多种,但是要无缝字符串拼接打印的可以这样
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name+':'+str(d.get(name))
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name+':'+str(d.get(name))
2018-11-27
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue;
else:
sum+=x;
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2 == 0:
continue;
else:
sum+=x;
print sum
2018-11-26
sum = 0
x = 1
n = 1
while True:
x = 2**(n-1);
print x
sum +=x
if n>=20:
break;
n +=1;
print sum
x = 1
n = 1
while True:
x = 2**(n-1);
print x
sum +=x
if n>=20:
break;
n +=1;
print sum
2018-11-26
sum = 0
x = 1
while x <= 100:
if x%2 !=0:
sum+=x;
x+=1;
print sum
x = 1
while x <= 100:
if x%2 !=0:
sum+=x;
x+=1;
print sum
2018-11-26
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
执行之后list长度有变化 再找低三个元素已经找不到了 故报错,换下执行顺序就好了
L.pop(3)
L.pop(2)
print L
执行之后list长度有变化 再找低三个元素已经找不到了 故报错,换下执行顺序就好了
2018-11-26
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.''' 这题目有点坑 ,中间得换行 而不是用\n在输出里实现换行效果
Whether it's nobler in the mind to suffer.''' 这题目有点坑 ,中间得换行 而不是用\n在输出里实现换行效果
2018-11-26
s = "Python was started in 1989 by \"Guido\".Python is free and easy to learn.\,"
2018-11-26
print('hello,');
print('python,');
print 'hello,','python,';
print('python,');
print 'hello,','python,';
2018-11-26
a = 45678;
b = 0X12fd2;
print(a+b);
print('Learn Python in imooc');
print(100<99);
print(0xff==255);
b = 0X12fd2;
print(a+b);
print('Learn Python in imooc');
print(100<99);
print(0xff==255);
2018-11-26
运行代码:
L=['Adam','Lisa','Bart','Pual']
s=[]
for i in range(1,10):
s.append(i)
print(list(zip(L,s)))
运行结果:[('Adam', 1), ('Lisa', 2), ('Bart', 3), ('Pual', 4)]
L=['Adam','Lisa','Bart','Pual']
s=[]
for i in range(1,10):
s.append(i)
print(list(zip(L,s)))
运行结果:[('Adam', 1), ('Lisa', 2), ('Bart', 3), ('Pual', 4)]