d = {'Alice': [50, 61, 66], 'Bob': [80, 61, 66], 'Candy': [88, 75, 90]}
for key in d:
value = d[key]
for ch in value:
print (key,ch)
for key in d:
value = d[key]
for ch in value:
print (key,ch)
2021-06-04
print("這是一句中英文混合的%s字符串:%s"%("python","Hello\tWorld"))
2021-06-02
template1="Life is short"
template2="you need python"
print("{0},{1}".format(template1,template2))
template="{L},{y}"
L="life is short"
y="you need python"
print(template.format(L=L,y=y))
template2="you need python"
print("{0},{1}".format(template1,template2))
template="{L},{y}"
L="life is short"
y="you need python"
print(template.format(L=L,y=y))
2021-06-02
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.''')
2021-06-02
L = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
S=[89, 72, 88, 79, 99]
Ss=[89, 72, 88, 79, 99]
def getnames(name):
return Ss.index(name)
S.sort(reverse=True);
for sa in S:
print(sa)
print(L[getnames(sa)])
print(r'''
''')
S=[89, 72, 88, 79, 99]
Ss=[89, 72, 88, 79, 99]
def getnames(name):
return Ss.index(name)
S.sort(reverse=True);
for sa in S:
print(sa)
print(L[getnames(sa)])
print(r'''
''')
2021-05-31
a = 'python'
print('hello,'+( a or 'world'))
b = ''
print('hello,'+(b or 'world'))
print('hello,'+( a or 'world'))
b = ''
print('hello,'+(b or 'world'))
2021-05-31
L = [95.5, 85, 59, 66, 72]
L.sort(reverse=True)
for i in range(3):
print(L[i])
L.sort(reverse=True)
for i in range(3):
print(L[i])
2021-05-29
c = '{0},{1}'
C=c.format('Life is short', 'you need Python')
print(C)
C=c.format('Life is short', 'you need Python')
print(C)
2021-05-27
d = {
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice']=[50, 61, 66]
d['Bob']=[80, 61, 66]
d['Candy']=[88, 75, 90]
for d1 in d:
name=d1
score=d.get(d1)
print('name={},score={}'.format(name,score))
'Alice': [45],
'Bob': [60],
'Candy': [75],
}
d['Alice']=[50, 61, 66]
d['Bob']=[80, 61, 66]
d['Candy']=[88, 75, 90]
for d1 in d:
name=d1
score=d.get(d1)
print('name={},score={}'.format(name,score))
2021-05-25
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for d1 in d:
print(d.get(d1))
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
for d1 in d:
print(d.get(d1))
2021-05-25
a =
if a <= 3:
print("baby")
else:
if a <=6:
print("kid")
else:
if a <=18:
print("teenager")
elif a >18:
print("adult")
if a <= 3:
print("baby")
else:
if a <=6:
print("kid")
else:
if a <=18:
print("teenager")
elif a >18:
print("adult")
2021-05-20
答案是錯的
函數(shù)定義的正確計算方式:
def sub_sum(L):
sum1 = 0
sum2 = 0
for item in L:
if item % 2 == 0:
sum1 += item
else:
sum2 += item
return sum1, sum2
函數(shù)定義的正確計算方式:
def sub_sum(L):
sum1 = 0
sum2 = 0
for item in L:
if item % 2 == 0:
sum1 += item
else:
sum2 += item
return sum1, sum2
2021-05-20