sum = 0
x = 1
n = 1
while True:
sum+=x
x+=x
n+=1
if n>20:
break
print sum
x = 1
n = 1
while True:
sum+=x
x+=x
n+=1
if n>20:
break
print sum
2019-09-23
s = 0
n = 1
a=1
while True:
a=a+3
s=a+s
n=n+1
if n >99:
break
s=s+1
print s
n = 1
a=1
while True:
a=a+3
s=a+s
n=n+1
if n >99:
break
s=s+1
print s
2019-09-22
def a(x, y, z):
b = x + (z - 1) * y
sum = z * (x + b) / 2
print(sum)
a(1, 3, 100)
b = x + (z - 1) * y
sum = z * (x + b) / 2
print(sum)
a(1, 3, 100)
2019-09-22
最赞回答 / 秦九州
dict 是无序的insert 中-1表示的是顺序,无序中找不到固定为-1顺序的内容和进行替代,因此dict中没有insert这是我认为的dict没有insert用法的原因
2019-09-22
N = 100
x = 0
L=[]
while x < N :
x= x+1
L.append(x)
sum = 0.00
for name in L:
if (name % 2) == 1:
print name
sum+=name
print sum
x = 0
L=[]
while x < N :
x= x+1
L.append(x)
sum = 0.00
for name in L:
if (name % 2) == 1:
print name
sum+=name
print sum
2019-09-22
L = ['Adam', 'Lisa', 'Bart']
L[-1],L[0] = L[0],L[-1]
print L
L[-1],L[0] = L[0],L[-1]
print L
2019-09-21
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
if key == 'Adam':
print key + ":" +str(d['Adam'])
if key == 'Lisa':
print key + ':' +str(d['Lisa'])
if key == 'Bart':
print key + ':' +str(d['Bart'])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
if key == 'Adam':
print key + ":" +str(d['Adam'])
if key == 'Lisa':
print key + ':' +str(d['Lisa'])
if key == 'Bart':
print key + ':' +str(d['Bart'])
2019-09-21
最新回答 / 椰汁菠萝
你报的啥错啊?你这代码写的没问题,不管你在哪里写的代码,运行报错都有很明确的提示,你的print f(3),f和括号之间的空格是认真的吗?你确定用的是python2.7.8?在python3中print已经没有这个语法了;命令行里多是做实验用的,真正开发的话肯定要在编译器里,比如,VSCode,idea之类的
2019-09-20