d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
dNew = {
'Alice': [50,61,66],
'Bob': [80,61,66],
'Candy': [88,75,90],
}
Name_L = ['Alice','Bob','Candy']
#循環L,逐個增加
for l in Name_L:
for s in range(0,3,1):
dnew_s = dNew[l][s]
d[l].append(dnew_s)
print(d)
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
dNew = {
'Alice': [50,61,66],
'Bob': [80,61,66],
'Candy': [88,75,90],
}
Name_L = ['Alice','Bob','Candy']
#循環L,逐個增加
for l in Name_L:
for s in range(0,3,1):
dnew_s = dNew[l][s]
d[l].append(dnew_s)
print(d)
2024-07-06
d = {
'Alice': [50, 61, 66],
'Bob': [80, 61, 66],
'Candy': [88, 75, 90]
}
for key, value in d.items():
index = 1
for item in value:
score = item
print('{name} 第{index}次成績:{score}'.format(name = key, index = index, score = score))
index += 1
'Alice': [50, 61, 66],
'Bob': [80, 61, 66],
'Candy': [88, 75, 90]
}
for key, value in d.items():
index = 1
for item in value:
score = item
print('{name} 第{index}次成績:{score}'.format(name = key, index = index, score = score))
index += 1
2024-06-19
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
M = []
for list in L:
num = 1
for item in list:
num = num * item
M.append(num)
print(M)
M = []
for list in L:
num = 1
for item in list:
num = num * item
M.append(num)
print(M)
2024-06-19
了解了true和false的判定規則會更容易理解這節課講的內容。
以下對象在布爾上下文中被視為 False:
None
False
數值 0(如 0, 0.0, 0j)
空序列(如 '', (), [])
空集合(如 {}, set())
空 range 對象(如 range(0))
除上述情況外,其他所有對象在布爾上下文中都被視為 True。
以下對象在布爾上下文中被視為 False:
None
False
數值 0(如 0, 0.0, 0j)
空序列(如 '', (), [])
空集合(如 {}, set())
空 range 對象(如 range(0))
除上述情況外,其他所有對象在布爾上下文中都被視為 True。
2024-06-18
list = [1,2,3,4,5,6,7,8,9,10]
sum = 1
for item in list:
sum = sum * (item + 1)
print(sum)
sum = 1
for item in list:
sum = sum * (item + 1)
print(sum)
2024-06-18
L = ['Alice', 66, 'Bob', True, 'False', 100]
for item in L[1::2]:
print (item)
for item in L[1::2]:
print (item)
2024-06-12
def greet(name="world"):
if name == "world":
print("Hello, world.")
else:
print(f"Hello, {name}.")
if name == "world":
print("Hello, world.")
else:
print(f"Hello, {name}.")
2024-05-17