# Enter a code
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
L.append('Zero')
L.append('Phoebe')
L.append('Gen')
L.sort()
print(L)
2023-12-27
T = ('Alice', 'Bob', 'Candy', 'David', 'Ellena')
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是David吧
# 通过下标的方式访问元素
print(T[0]) # ==> Alice
print(T[4]) # ==> Ellena
# 切片
print(T[1:3]) # ==> ('Bob', 'Candy')
candy错了吧,应该是David吧
2023-12-25
num = 3.14 * 1.57
print (round (num , 2))
round 需要嵌套在print里面
print (round (num , 2))
round 需要嵌套在print里面
2023-12-19
最赞回答 / 翎栋
L = [75, 92, 59, 68, 99]def avg(l): return sum(l) / len(l)def avg2(l): sum1 = 0 for i in l: sum1 += i return sum1 / len(l)average = avg2(L)print(average)
2023-12-19
直接使用 get 方法如果找不到默认返回 None 的特性,代码如下。
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for name in names :
print(d.get(name))
2023-12-13
最新回答 / weixin_慕无忌2350060
if not isinstance(x,int) or not isinstance(x,float):这里应该用and,否则任何类型进去都是true
2023-12-12
最新回答 / 慕UI2375754
不需要的,sum相当于一个无限大的容器,sum = sum+x,相当于把原本sum容器里的东西加上x再一起返回sum容器里面,sum1=sum+x应该理解为把 原本sum容器里的东西加上x放进sum1这个容器
2023-12-08
print(r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.''')
Whether it's nobler in the mind to suffer.''')
2023-12-07