最新回答 / mixuelantang
短路计算。真 and 假 总是输出假,所以True and 0输出0,你也说了False和0等价,所以输出0和输出False等价。假 or 真 总是输出真,是指输出真的那个语句,如果先赋值a = False, 0 or a 则输出False即a 的值
2020-10-08
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for key, name in zip(d.keys(), names):
if name in d.keys():
print(d.get(key))
else:
print(None)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
names = ["Alice", "Bob", "Candy", "Mimi", "David"]
for key, name in zip(d.keys(), names):
if name in d.keys():
print(d.get(key))
else:
print(None)
2020-10-03
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
score = [89, 72, 88, 79, 99]
for j in range(len(score)):
for i in range(len(names) - 1):
if score[i] > score[i + 1]:
temp = names[i]
names[i] = names[i + 1]
names[i + 1] = temp
print(names)
score = [89, 72, 88, 79, 99]
for j in range(len(score)):
for i in range(len(names) - 1):
if score[i] > score[i + 1]:
temp = names[i]
names[i] = names[i + 1]
names[i + 1] = temp
print(names)
2020-10-03
length =3.14
width=1.57
result=round(length*width)
print(result)
不用加变量类型和分号,简单的有点不习惯
width=1.57
result=round(length*width)
print(result)
不用加变量类型和分号,简单的有点不习惯
2020-09-30
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print (x + y + z)
print (x + z + y)
print (y + x + z)
print (y + z + x)
print (z + x + y)
print (z + y + x)
s2 = '123'
s3 = 'xyz'
for x in s1:
for y in s2:
for z in s3:
print (x + y + z)
print (x + z + y)
print (y + x + z)
print (y + z + x)
print (z + x + y)
print (z + y + x)
2020-09-30
最赞回答 / qq_慕神4044404
再少点是这样:L = ['Alice', 66, 'Bob', True, 'Flase', 100]for i in range(len(L)): if i % 2 == 0: print(L[i])
2020-09-29
已采纳回答 / qq_慕神4044404
students = ['Alice', 'Bob', 'Candy', 'Mimi', 'David']d = { 'Alice': 45, 'Bob': 60, 'Candy': 75, 'David': 86, 'Ellena': 49}for i in students: print(d.get(i))
2020-09-29
已采纳回答 / 咚咚呛
在这里,index表示的是item在L的位置,可以看到操作每个item之后,index都加1了。sum1 += x 是缩写,它等于sum1 = sum1 + x。
2020-09-29