# Enter a code
def square_of_sum(l):
sum=0
for x in l:
sum=sum+x*x
return(sum)
print(square_of_sum([2,6,4,5]))
def square_of_sum(l):
sum=0
for x in l:
sum=sum+x*x
return(sum)
print(square_of_sum([2,6,4,5]))
2021-11-13
# 要查找的姓名转换成小写,遍历的集合时,将成员也转换成小写,再遍历
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
namesInput = "ALICE".lower()
for name in name_set:
if namesInput == name.lower():
print("cun zai")
break #找到姓名时,就跳出循环
else:
print("mei you zhao dao")
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
name_set = set(names)
namesInput = "ALICE".lower()
for name in name_set:
if namesInput == name.lower():
print("cun zai")
break #找到姓名时,就跳出循环
else:
print("mei you zhao dao")
2021-11-10
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
list1 = d.keys()
print(len(list1))
list1 = d.keys()
print(len(list1))
2021-11-10
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for name in d.keys():
print(d[name])
for item in d.items():
print(item)
for key, value in d.items():
print(value)
for name in d.keys():
print(d[name])
for item in d.items():
print(item)
for key, value in d.items():
print(value)
2021-11-10
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for student in d.keys():
if student == "Alice":
print("Alice score is %s" %d[student])
d[student] = 60
print(d)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for student in d.keys():
if student == "Alice":
print("Alice score is %s" %d[student])
d[student] = 60
print(d)
2021-11-10
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
aliceScore = [50, 61, 66]
bobScore = [80, 61, 66]
candyScore = [88, 75, 90]
d["Alice"].append(aliceScore)
d["Bob"].append(bobScore)
d["Candy"].append(candyScore)
print(d)
记录一下下,
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
aliceScore = [50, 61, 66]
bobScore = [80, 61, 66]
candyScore = [88, 75, 90]
d["Alice"].append(aliceScore)
d["Bob"].append(bobScore)
d["Candy"].append(candyScore)
print(d)
记录一下下,
2021-11-10
tuple1 = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
count = 0
for i in tuple1:
if type(i) == tuple:
count += 1
print("number of tuple is %d " %count)
count = 0
for i in tuple1:
if type(i) == tuple:
count += 1
print("number of tuple is %d " %count)
2021-11-10
最新回答 / hermaniu
Python 3的版本中已经没有 cmp 函数,如果你需要实现比较功能,需要引入 operator 模块,适合任何对象,包含的方法有:
operator.lt(a, b)operator.le(a, b)operator.eq(a, b)operator.ne(a, b)operator.ge(a, b)operator.gt(a, b)
2021-11-10