# Enter a code
L = [95.5, 85, 59, 66, 72]
sub_L = L[0:3]
print(sub_L)
L = [95.5, 85, 59, 66, 72]
sub_L = L[0:3]
print(sub_L)
2021-06-24
a=0
L = ['Alice', 66, 'Bob', True, 'False', 100]
for item in L:
a=a+1
if a % 2 == 0:
print(item)
L = ['Alice', 66, 'Bob', True, 'False', 100]
for item in L:
a=a+1
if a % 2 == 0:
print(item)
2021-06-24
>>> names=['Alice','Bob','Candy','David','Ellena']
>>> names.append('Zero')
>>> names.insert(5, 'Gen')
>>> names.insert(6, 'Phoebe')
>>> print(names)
['Alice', 'Bob', 'Candy', 'David', 'Ellena', 'Gen', 'Phoebe', 'Zero']
應該是上面這樣吧,按照參考答案的話 'Gen', 'Phoebe'會反過來
>>> names.append('Zero')
>>> names.insert(5, 'Gen')
>>> names.insert(6, 'Phoebe')
>>> print(names)
['Alice', 'Bob', 'Candy', 'David', 'Ellena', 'Gen', 'Phoebe', 'Zero']
應該是上面這樣吧,按照參考答案的話 'Gen', 'Phoebe'會反過來
2021-06-24
L = [95.5,85,59,66,72]
>>> print(L[-5],L[-4],L[-1])
95.5 85 72
>>> print(L[-5],L[-4],L[-1])
95.5 85 72
2021-06-24
>>> L = [95.5,85,59,66,72]
>>> print(L[0,1,4])
Traceback (most recent call last):
File "<pyshell#102>", line 1, in <module>
print(L[0,1,4])
TypeError: list indices must be integers or slices, not tuple
>>> print(L[0],L[1],L[4])
95.5 85 72
>>> print(L[0,1,4])
Traceback (most recent call last):
File "<pyshell#102>", line 1, in <module>
print(L[0,1,4])
TypeError: list indices must be integers or slices, not tuple
>>> print(L[0],L[1],L[4])
95.5 85 72
2021-06-24
# Enter a code
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
d['Alice']=(d['Alice'],60) #最賴的辦法
print (d)
d = {
'Alice': 45,
'Bob': 60,
'Candy': 75,
'David': 86,
'Ellena': 49
}
d['Alice']=(d['Alice'],60) #最賴的辦法
print (d)
2021-06-21
# Enter a code
T=(1,'CH',[3,4])
L=list(T)
L[2]=tuple(L[2])
T=tuple(L)
print(T)
T=(1,'CH',[3,4])
L=list(T)
L[2]=tuple(L[2])
T=tuple(L)
print(T)
2021-06-21
l=['Alice','Bob','Candy','David','Ellena']
s=[89,72,88,79,99]
k=[]
i=0
for ch in l:
k.append([ch,s[i]])
i=i+1
s.sort(reverse=True)
m=[]
for ch in s:
for p in k:
if p[1]==ch:
m.append("{}-{}".format(p[0],ch))
break
print(m)
s=[89,72,88,79,99]
k=[]
i=0
for ch in l:
k.append([ch,s[i]])
i=i+1
s.sort(reverse=True)
m=[]
for ch in s:
for p in k:
if p[1]==ch:
m.append("{}-{}".format(p[0],ch))
break
print(m)
2021-06-20
cou=['Chinese','Math','English'];ach=[92,75,99]
i=0
for x in cou:
print("{}:{}".format(x,ach[i]))
i=i+1
i=0
for x in cou:
print("{}:{}".format(x,ach[i]))
i=i+1
2021-06-20
a='Life is short, {}.'
b='you need python'
c=a.format(b)
print(c)#=
or
a='Life is short, {}.'
c=a.format('you need python')
print(c)#=
b='you need python'
c=a.format(b)
print(c)#=
or
a='Life is short, {}.'
c=a.format('you need python')
print(c)#=
2021-06-19