# coding=utf-8
def sub_sum(L):
num=1
sum=0
sum2=0
for i in L:
if num%2!=0:
sum=sum+i
num=num+1
else:
sum2=sum2+i
num=num+1
return sum,sum2
A=[1,2,3,4,5,6,7,8,9]
print(sub_sum(A))
def sub_sum(L):
num=1
sum=0
sum2=0
for i in L:
if num%2!=0:
sum=sum+i
num=num+1
else:
sum2=sum2+i
num=num+1
return sum,sum2
A=[1,2,3,4,5,6,7,8,9]
print(sub_sum(A))
2021-07-22
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
num=0
while num<10:
if L[num] in S:
S.remove(L[num])
num=num+1
else:
S.add(L[num])
num=num+1
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
num=0
while num<10:
if L[num] in S:
S.remove(L[num])
num=num+1
else:
S.add(L[num])
num=num+1
print(S)
2021-07-21
# Enter a code
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L1=[50,61,66]
L2=[80,61,66]
L3=[88,75,90]
num=0
while num<3:
d['Alice'].append(L1[num])
d['Bob'].append(L2[num])
d['Candy'].append(L3[num])
num=num+1
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
L1=[50,61,66]
L2=[80,61,66]
L3=[88,75,90]
num=0
while num<3:
d['Alice'].append(L1[num])
d['Bob'].append(L2[num])
d['Candy'].append(L3[num])
num=num+1
print(d)
2021-07-21
已采纳回答 / qq_冰红茶小哥
不对,嵌套for循环,走外面的for循环取L值,里面的for循环取S值,值会重复,例如外面取1,里面取3,1==3,就会执行add方法,没有实现你想要的。只要遍历一遍就可以,判断从L中取得值与S中的值一不一样就可以了
2021-07-19
已采纳回答 / 慕后端4297166
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']new_names=[]for i in names: name_lower=i.lower() new_names.append(name_lower)# print(new_names)if 'bob' in new_names: print('yep')else: print('None')
2021-07-19
最赞回答 / 慕移动1463139
每轮for循环会输出一个结果,因为dict中有三个key,d.keys()在这里的结果是一个含有三个key的list,for 循环执行了三次,故有三个结果,3代表的是字符串‘Bob’的长度,后面的两个5分别代表字符串‘Alice’和字符串‘Candy’的长度
2021-07-19
# Enter a code
L = [75, 92, 59, 68, 99]
sum =0.0
l=0
for x in L:
sum=sum+x
l=l+1
print(sum/l)
L = [75, 92, 59, 68, 99]
sum =0.0
l=0
for x in L:
sum=sum+x
l=l+1
print(sum/l)
2021-07-19
最新回答 / 慕尼黑7378605
WIN +R CMD 如果python配置了环境变量,直接输入 PYTHON,没有的话到CMD 到PYTHON 的安装目录bin文件夹,输入PYTHON
2021-07-19
最新回答 / qq_精慕门9151183
alice_score= d.pop('Alice')这里已经把Alice从d里面删掉了,因为d里面已经没有Alice了,后面再用pop就会报错
2021-07-18
……是不是出错了
应该是“所有字符的组合”而非“所有字符的排列”
如果是排列的话好像要在设置的s1 s2 s3里面再设置循环吧……
应该是“所有字符的组合”而非“所有字符的排列”
如果是排列的话好像要在设置的s1 s2 s3里面再设置循环吧……
2021-07-18
print(
r'''"To be, or not to be":that is the question.
Whether it'snobler in the mind to suffer.''')
r'''"To be, or not to be":that is the question.
Whether it'snobler in the mind to suffer.''')
2021-07-16
已采纳回答 / 慕村4040375
not isinstance(L,list) or not isinstance(L,tuple)这个条件相当于L既是list也是tuple才是false,实际上L只能是list,或者只能是tuple,所以条件就永远都是true可以试试改成not isinstance(L,list) and not isinstance(L,tuple),或者not (isinstance(L,list) or isinstance(L,tuple))
2021-07-15