names=['Alice', 'Bob', 'Candy', 'David', 'Ellena']
names.append('Zero')
names.insert(5,'Phoebe')
names.insert(5,'Gen')
print(names)
names.append('Zero')
names.insert(5,'Phoebe')
names.insert(5,'Gen')
print(names)
2021-01-20
s1='abc'
s2='123'
s3='xyz'
for j in s1:
for k in s2:
for l in s3:
print(j+k+l)
s2='123'
s3='xyz'
for j in s1:
for k in s2:
for l in s3:
print(j+k+l)
2021-01-20
num = 1
sum = 1
while num <= 10:
sum = sum*num
num = num+1
print(sum)
sum = 1
while num <= 10:
sum = sum*num
num = num+1
print(sum)
2021-01-20
age = 2
if age >= 18:
print('adult')
elif age > 6:
print("teenager")
elif age > 3:
print('kid')
else:
print('baby')
if age >= 18:
print('adult')
elif age > 6:
print("teenager")
elif age > 3:
print('kid')
else:
print('baby')
2021-01-19
age = 18
if age >= 18:
print('adult')
else:
print('teenage')
if age >= 18:
print('adult')
else:
print('teenage')
2021-01-19
template='life is {s},you need {p}'
short='short'
python='python'
result=template.format(s=short,p=python)
print(result)
template='life {}'
result=template.format("is short,you need python.")
print(result)
short='short'
python='python'
result=template.format(s=short,p=python)
print(result)
template='life {}'
result=template.format("is short,you need python.")
print(result)
2021-01-19
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
score = {
'Alice':[50, 61, 66],
'Bob':[80, 61, 66],
'Candy':[88, 75, 90]
}
name = ['Alice','Bob','Candy']
for n in name:
i = 0
while i<=2:
d[n].append(score[n][i])
i += 1
print(d)
參考答案感覺太傻,還是循環舒服
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
score = {
'Alice':[50, 61, 66],
'Bob':[80, 61, 66],
'Candy':[88, 75, 90]
}
name = ['Alice','Bob','Candy']
for n in name:
i = 0
while i<=2:
d[n].append(score[n][i])
i += 1
print(d)
參考答案感覺太傻,還是循環舒服
2021-01-18
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
name = 'Alice'
if name in d.keys():
d.pop(name)
print(d)
else:
print('{} not in d'.format(name))
# 當key不存在的時候,但是名字存在呀,所以把名字找出來定義了,然后刪除名字,再輸入,就可以得到了
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
name = 'Alice'
if name in d.keys():
d.pop(name)
print(d)
else:
print('{} not in d'.format(name))
# 當key不存在的時候,但是名字存在呀,所以把名字找出來定義了,然后刪除名字,再輸入,就可以得到了
2021-01-17
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice'] = [50,61,77]
d['Bob'] = [80,61,66]
d['Candy'] = [88,75,90]
print(d)
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice'] = [50,61,77]
d['Bob'] = [80,61,66]
d['Candy'] = [88,75,90]
print(d)
2021-01-17
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49,
}
print(d.get('Alice'))
print(d.get('Bob'))
print(d.get('Candy'))
print(d.get('David'))
print(d.get('Mimi'))
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49,
}
print(d.get('Alice'))
print(d.get('Bob'))
print(d.get('Candy'))
print(d.get('David'))
print(d.get('Mimi'))
2021-01-16