L = [75, 92, 59, 68]
sum = 0.0
for nub in L:
sum+=nub
print sum / 4
sum = 0.0
for nub in L:
sum+=nub
print sum / 4
2020-07-13
sum = 0
x = 1
while x <= 100:
if not x % 2 == 0:
sum += x
x += 1
print sum
x = 1
while x <= 100:
if not x % 2 == 0:
sum += x
x += 1
print sum
2020-07-12
def square_of_sum(x):
sum=0
for a in x:
if isinstance(a,int):
b=a*a
sum=b+sum
print "sum:",sum
else:
return "Error Type, Please input int type"
return sum
sum=0
for a in x:
if isinstance(a,int):
b=a*a
sum=b+sum
print "sum:",sum
else:
return "Error Type, Please input int type"
return sum
2020-07-10
已采纳回答 / 绿鲤鱼8119299
s=set( list [ tuple (), tuple (), tuple () ] ) 这个set中的元素是tuple类型,每个tuple包含两个元素for x in s 中的 x 是一个 tuple, tuple 中的元素不能修改,只能访问,访问方式和链表一样用 [索引],即 x[0],x[1]
2020-07-09
#-*-coding:utf-8-*-#
print 7777+999
print"Learn Python in imooc。"
print 100<99
print 0xff==255
print 7777+999
print"Learn Python in imooc。"
print 100<99
print 0xff==255
2020-07-09
print("Learn Python in imooc.");就可以
print("Learn Python in imooc。");就不行
需要在前面添加#-*-coding:utf-8-*-#
print("Learn Python in imooc。");就不行
需要在前面添加#-*-coding:utf-8-*-#
2020-07-09
L = [75, 92, 59, 68]
sum = 0.0
count=0
for val in L:
sum=sum+val
count=count+1
print sum / count
如果有表示数组内元素数量的函数,就可以消灭count了
sum = 0.0
count=0
for val in L:
sum=sum+val
count=count+1
print sum / count
如果有表示数组内元素数量的函数,就可以消灭count了
2020-07-08
已采纳回答 / 嘟嘟_dd123
假设第一次进入循环,此时x = 0先打印再计算:先打印当前x的值再让x自增1,最后打印x为0先计算再打印:先让x自增1再打印x的值,此时打印的x是自增1后的值,也就是1
2020-07-06
已采纳回答 / williamgjn
在你这个代码中,首先定义了x1, d, n这三个变量,最后计算了x100(同时也声明了x100这个变量),所以这段代码就没有计算x99的值,最后也就会报错。简单一点的方法当然是单独算了,不需要多的代码知识。复杂一点你可以创建一个list(后面的章节有),用for循环全算出来,把结果依次存储到list中。<...code...>
2020-07-05
L = range(1, 101)
L1 =[]
L2=[]
print L[0:10]
for x in L:
if x%3==0:
L1.append(x)
print L1
for y in L:
if y<=50 and y%5==0:
L2.append(y)
print L2
print L[2::3]
print L[4:50:5]
L1 =[]
L2=[]
print L[0:10]
for x in L:
if x%3==0:
L1.append(x)
print L1
for y in L:
if y<=50 and y%5==0:
L2.append(y)
print L2
print L[2::3]
print L[4:50:5]
2020-07-03