L = []
for a in range(101):
if a != 0:
L.append(a)
print(L)
sum = 0
for x in L:
sum = sum + x * x
print(sum)
for a in range(101):
if a != 0:
L.append(a)
print(L)
sum = 0
for x in L:
sum = sum + x * x
print(sum)
2023-06-25
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for a in L:
if a in S:
S.remove(a)
else:
S.add(a)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for a in L:
if a in S:
S.remove(a)
else:
S.add(a)
print(S)
2023-06-25
# Enter a code
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
score = []
for name in d:
print(name)
score.append(d[name])
for key in list(d.keys()):
if key in d:
d.pop(key)
print(score)
print(d)
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
score = []
for name in d:
print(name)
score.append(d[name])
for key in list(d.keys()):
if key in d:
d.pop(key)
print(score)
print(d)
2023-06-24
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
if 'Alice' in d:
score = d['Alice']
print(score)
d['Alice'] = 60
print(d)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
if 'Alice' in d:
score = d['Alice']
print(score)
d['Alice'] = 60
print(d)
2023-06-24
ju = [[1,2,3],[5,3,2],[7,3,2]]
print(ju)
a = 0
for a in range(len(ju)):
print(ju[a][0]*ju[a][1]*ju[a][2])
a += 1
print(ju)
a = 0
for a in range(len(ju)):
print(ju[a][0]*ju[a][1]*ju[a][2])
a += 1
2023-06-23
最贊回答 / weixin_慕工程7111902
Computer regarded your『('17')』 of? ?『age=('17')』 as a 'string',not a 'number'.So it's working like down hereelse:? ? ? print('adult')If you change your code from____________________________________age=('17')? ? ? &------------------------...
2023-06-13
set提供isdisjoint()方法,可以快速判斷兩個集合是否有重合,如果有重合,返回False。##竟然記反了
2023-06-12
有一種方法可以通過key來獲取對應的value,這種方法不會引起錯誤,dict本身提供get方法,把key當作參數(shù)傳遞給get方法,就可以獲取對應的value,當key不存在時,也不會報錯,而是返回None。
2023-06-11
已采納回答 / 慕工程9338430
這是個死循環(huán)當num為奇數(shù)時,跳過了,下面的都不會執(zhí)行,直接到下次而下一次還是執(zhí)行奇數(shù),就會這樣一直循環(huán),所以運行不出來試試這個num?=?1result?=?0while?num?<=?1000:????if?num?%?2?==?1:????????num?+=?1? ? ? ??continue????result?+=?num????num?+=?1print(result)
2023-06-06
# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
n1=0
for name in L:
if L[n1]=='Candy':
L.pop(n1)
else:
n1+=1
n2=0
for name in L:
if L[n2]=='David':
L.pop(n2)
else:
n2+=1
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
n1=0
for name in L:
if L[n1]=='Candy':
L.pop(n1)
else:
n1+=1
n2=0
for name in L:
if L[n2]=='David':
L.pop(n2)
else:
n2+=1
print(L)
2023-06-05