# coding=utf-8
def sub_sum():
ouSum = 0
jiSum = 0
for i in L:
if i%2==0:
ouSum += i
else:
jiSum += i
return ouSum,jiSum
L = [1,2,3,4,5,6,7,8,9]
print(sub_sum())
def sub_sum():
ouSum = 0
jiSum = 0
for i in L:
if i%2==0:
ouSum += i
else:
jiSum += i
return ouSum,jiSum
L = [1,2,3,4,5,6,7,8,9]
print(sub_sum())
2022-08-24
# Enter a code
L = [1,2,3,4,5]
def square_of_sum():
sum = 0
for i in L:
sum += i*i
return sum
print(square_of_sum())
L = [1,2,3,4,5]
def square_of_sum():
sum = 0
for i in L:
sum += i*i
return sum
print(square_of_sum())
2022-08-24
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
for i in s1:
for j in s2:
if i==j:
print(j)
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if not s1.isdisjoint(s2):
for i in s1:
for j in s2:
if i==j:
print(j)
2022-08-22
# Enter a code
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
count = 0
for i in d:
count += 1
print(count)
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
count = 0
for i in d:
count += 1
print(count)
2022-08-21
# Enter a code
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for i in d.keys():
print('{}: {}'.format(i,d[i]))
d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for i in d.keys():
print('{}: {}'.format(i,d[i]))
2022-08-21
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
oldResult = d['Alice']
d['Alice'] = 60
print(d)
print(oldResult)
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
oldResult = d['Alice']
d['Alice'] = 60
print(d)
print(oldResult)
2022-08-21
# Enter a code
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
d['Alice'] = 60
print(d)
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
d['Alice'] = 60
print(d)
2022-08-21
# Enter a code
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice'] = [50,61,66]
d['Bob'] = [80,61,66]
d['Candy'] = [88,75,90]
print(d)
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice'] = [50,61,66]
d['Bob'] = [80,61,66]
d['Candy'] = [88,75,90]
print(d)
2022-08-21
# Enter a code
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
print(T)
T = ((1+2), ((1+2),), ('a'+'b'), (1, ), (1,2,3,4,5))
print(T)
2022-08-20
# Enter a code
result = (100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100)
counts = result.count(100)
print(counts)
result = (100, 69, 29, 100, 72, 99, 98, 100, 75, 100, 100, 42, 88, 100)
counts = result.count(100)
print(counts)
2022-08-20
# Enter a code
TextTuple = tuple(range(10))
print(TextTuple)
TextList = list(TextTuple)
print(TextList)
TextTuple = tuple(range(10))
print(TextTuple)
TextList = list(TextTuple)
print(TextList)
2022-08-20
# Enter a code
TextTuple = (0,1,2,3,4,5,6,7,8,9)
print(TextTuple)
TextList = list(TextTuple)
print(TextList)
TextTuple = (0,1,2,3,4,5,6,7,8,9)
print(TextTuple)
TextList = list(TextTuple)
print(TextList)
2022-08-20
# coding: utf-8
s=r'''这是一句中英文混合的Python字符串:
Hello World!'''
print(s)
s=r'''这是一句中英文混合的Python字符串:
Hello World!'''
print(s)
2022-08-19
#the first
template='life is {0}, you need {1}.'
result=template.format('short','Python')
print(result)
#the second
template='you need {p}, life is {s}.'
short='short'
Python='Python'
result=template.format(p=Python, s=short)
print(result)
template='life is {0}, you need {1}.'
result=template.format('short','Python')
print(result)
#the second
template='you need {p}, life is {s}.'
short='short'
Python='Python'
result=template.format(p=Python, s=short)
print(result)
2022-08-19
# Enter a code
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for x in L:
length = x[0]
width = x[1]
height = x[2]
result = (length*width+length*height+width*height)*2
print(result)
L = [[1, 2, 3], [5, 3, 2], [7, 3, 2]]
for x in L:
length = x[0]
width = x[1]
height = x[2]
result = (length*width+length*height+width*height)*2
print(result)
2022-08-19