def my_func(x):
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
num = 1
for item in x:
num = item*num
return num
x = (12, 34, 56, 43, 65)
print(my_func(x))
if isinstance(x, list):
return sum(x)
elif isinstance(x, tuple):
num = 1
for item in x:
num = item*num
return num
x = (12, 34, 56, 43, 65)
print(my_func(x))
2023-10-03
def sub_sum(l):
sum_even = 0
sum_odd = 0
for num in l:
if num % 2 == 0:
sum_even = num + sum_even
else:
sum_odd = num + sum_odd
return sum_even, sum_odd
l = [1,2,3,4,5,6,7,8,9,10]
sum_even, sum_odd = sub_sum(l)
print(sub_sum(l))
sum_even = 0
sum_odd = 0
for num in l:
if num % 2 == 0:
sum_even = num + sum_even
else:
sum_odd = num + sum_odd
return sum_even, sum_odd
l = [1,2,3,4,5,6,7,8,9,10]
sum_even, sum_odd = sub_sum(l)
print(sub_sum(l))
2023-10-02
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if s1.isdisjoint(s2)==False:
for numbers_overlap in s1:
if numbers_overlap in s2:
print(numbers_overlap)
#so if there are numbers(numbers_overlap) in s1 found in set 2, print the numbers_overlap
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if s1.isdisjoint(s2)==False:
for numbers_overlap in s1:
if numbers_overlap in s2:
print(numbers_overlap)
#so if there are numbers(numbers_overlap) in s1 found in set 2, print the numbers_overlap
2023-09-28
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
# if ( item_L) is in S, it should be deleted from set, if not, it should be added into set.
for item_L in L:
if item_L in S:
S.remove(item_L)
else:
S.add(item_L)
print(S)
S = set([1, 3, 5, 7, 9, 11])
# if ( item_L) is in S, it should be deleted from set, if not, it should be added into set.
for item_L in L:
if item_L in S:
S.remove(item_L)
else:
S.add(item_L)
print(S)
2023-09-28
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for i in L:
S1 = S
S1.add(i)
if S != S1:
S.add(i)
S1.remove(i)
else:
S.remove(i)
print(S)
S = set([1, 3, 5, 7, 9, 11])
for i in L:
S1 = S
S1.add(i)
if S != S1:
S.add(i)
S1.remove(i)
else:
S.remove(i)
print(S)
2023-09-19
最新回答 / 精慕門3179895
# Enter a code# coding=utf-8score = 59if score < 60:? ? print('抱歉,考試不及格')
2023-09-10
最新回答 / 慕桂英0103340
在if語句的上一行,應該要對s進行定義例如;s=19if s>17:? ? print('adult',s)結果會輸出為;adult? ?19
2023-09-04
最新回答 / qq_慕神6096684
#Enter a code翻譯:#請輸入代碼A='AABCDEFGHHIJ'翻譯:A是變量名,定義A=AABCDEFGHHIJS=A[1:9]翻譯:S也是變量名,定義S=A的第2到8位(在程序的世界中,第一個數字是0)print(S)翻譯:print(打印),S(變量名);print(S)打印S的意思,結果是:ABCDEFGH
2023-08-20
最新回答 / 慕運維2498310
變量名由大小寫英文字母、數字和下劃線_組成變量不能用數字開頭變量盡量不要和Python關鍵字重合(比如前面學習過的:and、or、not,否則可能導致Python原有關鍵字發揮不出作用)
2023-08-14