# Enter a code
a = 'python'
print('hello,', a or 'world')
# 因為a的值是True所以選擇a的值輸出而不選擇后面的world
b = ' '
print('hello,', b or 'world')
# 因為b是False,但是后面world是True,又因為使用的是or語句所以只要有一個是True答案都是True所以輸出b的值
a = 'python'
print('hello,', a or 'world')
# 因為a的值是True所以選擇a的值輸出而不選擇后面的world
b = ' '
print('hello,', b or 'world')
# 因為b是False,但是后面world是True,又因為使用的是or語句所以只要有一個是True答案都是True所以輸出b的值
2021-01-30
def sub_sum(li):
odd_num_sum = even_num_sum = 0
for i in li:
if i % 2 == 0:
even_num_sum += i
else:
odd_num_sum += i
return odd_num_sum, even_num_sum
odd_num, even_num = sub_sum([1, 2, 3, 4, 5, 6])
print(f'奇數和:{odd_num}, 偶數和:{even_num}')
odd_num_sum = even_num_sum = 0
for i in li:
if i % 2 == 0:
even_num_sum += i
else:
odd_num_sum += i
return odd_num_sum, even_num_sum
odd_num, even_num = sub_sum([1, 2, 3, 4, 5, 6])
print(f'奇數和:{odd_num}, 偶數和:{even_num}')
2021-01-30
def square_of_sum(li):
return sum(i ** 2 for i in li)
result = square_of_sum([1, 2, 3])
print(result)
return sum(i ** 2 for i in li)
result = square_of_sum([1, 2, 3])
print(result)
2021-01-30
s1 = {1, 2, 3, 4, 5}
s2 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
if not s1.isdisjoint(s2):
s_new = s2 - s1
print(s_new)
else:
print('無重合!')
s2 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
if not s1.isdisjoint(s2):
s_new = s2 - s1
print(s_new)
else:
print('無重合!')
2021-01-30
L = ['Alice', 66, 'Bob', True, 'False', 100]
for item in L:
if L.index(item) % 2 != 0:
print(item)
for item in L:
if L.index(item) % 2 != 0:
print(item)
2021-01-30
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s2&s1)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
print(s2&s1)
2021-01-26
# Enter a code
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d ['Alice']=[50, 61, 66]
d ['Bob'] =[80, 61, 66]
d ['Candy']=[88, 75, 90]
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d ['Alice']=[50, 61, 66]
d ['Bob'] =[80, 61, 66]
d ['Candy']=[88, 75, 90]
print(d)
2021-01-24
# Enter a code
T =(100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100)
print (T.count(100))
T =(100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100)
print (T.count(100))
2021-01-24